Configure Apache + PHP + MySQL in Mac OS x in detail

Source: Internet
Author: User
Tags bz2 mcrypt sqlite zts phpmyadmin



This is a super detailed configuration of Mac OS under the Php+mysql+apache article. Very detailed
Most of my configuration is to refer to the above content, for example, PHP can not connect to the database, is to change the default php.ini in the Pdo_mysql.default_socket "because now all use PDO." No MySQL connection library. "
Because I am using navicat, so to phpmyadmin that piece of configuration is not very concerned about. However, the installation of MCrypt can be consulted.
Original from: Configure Apache + PHP + MySQL in Mac OS X
The contents are as follows:



Mac OS X has built-in Apache and PHP, which makes it easy to use. This article takes Mac OS X 10.6.3 as an example. The main contents include:


    1. Launch Apache
    2. Running PHP
    3. Install MySQL
    4. Using phpMyAdmin
    5. Configuring PHP's MCrypt Extension library
    6. Set up a virtual host
Launch Apache


There are two ways of doing this:


    1. Open Web share (Web sharing), System settings Preferences (Preferences), sharing (sharing)
    2. Open terminal (terminal), then (note: sudo requires a password that is the root account password of the system)
      1. Run "sudo apachectl start" and enter your account password so that Apache runs.
      2. Run "sudo apachectl-v" and you will see the Apache version number in Mac OS X 10.6.3:
        Server version:apache/2.2.14 (Unix) server built:   Feb 11 2010 14:40:31


This allows you to enter "http://localhost" in the browser, and you can see that a content "It works!" appears Page, which is located under "/library (Resource Library)/webserver/documents/", which is the default root directory for Apache.






NOTE: When Apache is turned on, "web sharing" is turned on, and the networked user accesses the "/library (library)/webserver/documents/" directory via "http://[local ip]/", via "http://[local IP" /~[user Name] "To access the/users/[user name]/sites/" directory, you can disable this access by setting the "Firewall (Firewall)" in "Security" in System preferences.


Running PHP
    1. Run "sudo vi/etc/apache2/httpd.conf" in the terminal to open the Apache configuration file. (If you are not accustomed to the terminal and VI can be set in the Finder to display all the system hidden files, remember the need to restart the Finder, so that you can find the corresponding files, edit as you like, but you need to note that some of the file changes need to open the root account, But on the whole it is safe to use sudo on the terminal to temporarily gain root privileges. )
    2. Find "#LoadModule php5_module libexec/apache2/libphp5.so", remove the previous #, Save (enter: W at the command line) and Exit VI (enter: Q on the command line).
    3. Run "sudo cp/etc/php.ini.default/etc/php.ini" so that you can configure various PHP functions via php.ini. Like what:
      Adjust the maximum value of the PHP submission file by the following two items,such as the maximum value of imported data in phpMyAdmin upload_max_filesize = 2M post_max_size = 8M; 
      for example, display_errors to control whether to display the error of the PHP program display_errors = Off
      

    4. Run "sudo apachectl restart" and restart Apache so PHP is ready to use.
    5. Run "cp/library/webserver/documents/index.html.en/library/webserver/documents/info.php", That is, copy the Index.html.en file and rename it to info.php in the root directory of Apache.
    6. Run "vi/library/webserver/document/info.php" in the terminal so that you can edit the info.php file in VI. In "It s works!" Add the following "<?php Phpinfo ();?>" and save it. This allows you to see information about PHP in http://localhost/info.php, such as the version number 5.3.1.
Install MySQL


Since MySQL is not preinstalled in Mac OS X, it needs to be installed manually, and the most stable version of MySQL is now 5.1. MySQL provides installation instructions under Mac OS x.


    1. Download MySQL 5.1. Select the appropriate version, for example, MYSQL-5.1.46-OSX10.6-X86_64.DMG is selected here.
    2. Run DMG and you will find 4 files inside. First click Install Mysql-5.1.46-osx10.6-x86_64.pkg, which is the main installation package for MySQL. In general, the installation file will automatically install MySQL to the folder under the same name under/usr/local. For example, clicking Run "mysql-5.1.46-osx10.6-x86_64.dmg" will install mysq into "/usr/local/mysql-5.1.46-osx10.6-x86_64". The default installation is complete.
    3. Click Install 2nd file mysqlstartupitem.pkg, so that MySQL will automatically start automatically when the boot.
    4. Click Install 3rd file Mysql.prefpane, so you will see icon named "MySQL" in "System Preferences", through which you can set MySQL to start or stop, and whether to run automatically when booting. The basic installation of MySQL is complete here.
    5. Add MySQL and mysqladmin aliases to bash's configuration file by running "sudo vi/etc/bashrc"
      #mysql alias mysql= '/usr/local/mysql/bin/mysql ' Alias mysqladmin= '/usr/local/mysql/bin/mysqladmin '

      This can be relatively simple in the terminal by the command to do the corresponding operation, such as after the installation is complete after the root default password is empty, if you want to set the password can be run in the terminal "Mysqladmin-u root password" Mysqlpassword "" to set up, Where Mysqlpassword is the root password. For more information, see b.5.4.1. How to Reset the Root Password.


Note: Mac OS x upgrades or other causes may cause MySQL to boot or boot automatically, and on the MySQL operator panel you will be prompted "Warning:the/usr/local/mysql/data directory is not owned by The ' MySQL ' or ' _mysql ', or under the command line prompt "Can ' t connect to local MySQL server through socket '/tmp/mysql.sock ' (2)", which should be caused in some case/ Usr/local/mysql/data's host has changed, just run "sudo chown-r mysql/usr/local/mysql/data".



Also, using PHP to connect MySQL may error "can ' t connect to local MySQL server through socket '/var/mysql/mysql.sock '", Or use localhost can not connect to MySQL and need 127.0.0.1, because the connection time PHP by default to find/var/mysql/mysql.sock, but Mac version of MySQL changed the location of the file, put in/tmp. The approach is to modify php.ini as follows:


Mysql.default_socket =/tmp/mysql.sock
Using phpMyAdmin


phpMyAdmin is a PHP-developed program for managing MySQL, which is very popular and practical. The ability to use phpMyAdmin to manage MySQL is a very effective way to test the results of the previous steps.


    1. Download phpMyAdmin. Choose the right version, such as the one I chose is the phpmyadmin-3.3.2-all-languages.tar.bz2 version.
    2. Copy the Phpmyadmin-3.32-all-languages folder in "Download (downloads)" To "/users/[user name]/sites" with the name renamed phpMyAdmin.
    3. Copy the config.sample.inc.php in "/users/[User name]/sites/phpmyadmin/" and name it config.inc.php
    4. Open config.inc.php and make the following changes:
      For cookie encryption, random long string $cfg['blowfish_secret'] = '';
      When "#2002 can't log in to MySQL server" appears in phpMyAdmin, 
      please change localhost to 127.0.0.1, this is because The MySQL daemon does IP binding (bind-address =127.0.0.1) resulting in $cfg['Servers'][$i]['host'] = 'localhost'; 
      change false to true so that you can access Passwordless MySQL, 
      even if MySQL has set a password, you can set this, 
      and then enter the password $cfg['Servers'][$i]['AllowNoPassword'] = false when logging in to phpMyAdmin;
    5. This allows the phpMyAdmin to be accessed through the http://localhost/~[user name]/phpmyadmin. At this point, I see a hint. "Unable to load the mcrypt extension, please check your PHP configuration. ", this involves installing the mcrypt extension in the next section.
Configuring PHP's MCrypt Extension


MCrypt is a powerful encryption algorithm extension library, which includes 22 algorithms, phpMyAdmin relies on this PHP extension library. But its installation under Mac OS X is less friendly, as follows:


  1. Download and unzip the libmcrypt-2.5.8.tar.bz2.
  2. Execute the following command at the terminal (note that the following commands are required to install Xcode support): xml/html code
    1. CD ~/downloads/libmcrypt-2.5.8/
    2. ./configure--disable-posix-threads--enable-static
    3. Make
    4. sudo make install
  3. Download and unzip php source file php-5.3.1.tar.bz2. The PHP version preinstalled in Mac OS X 10.6.3 is 5.3.1, and now the latest PHP version is 5.3.2, you need to choose the appropriate version according to your actual situation.
  4. Execute the following command at the terminal: xml/html code
    1. CD ~/downloads/php-5.3.1/ext/mcrypt
    2. Phpize
    3. ./configure
    4. Make
    5. CD modules
    6. sudo cp mcrypt.so/usr/lib/php/extensions/no-debug-non-zts-20090626/
  5. Open php.ini
    sudo vi/etc/php.ini

    Add the following code to the php.ini, save and exit, then restart Apache

    Extension=/usr/lib/php/extensions/no-debug-non-zts-20090626/mcrypt.so


When you revisit http://localhost/~[username]/phpmyadmin, you will find "unable to load the mcrypt extension, please check your PHP configuration." "The hint is gone, which means the MCrypt expansion Library was installed successfully.


Set up a virtual host
  1. Run "sudo vi/etc/apache2/httpd.conf" on the terminal to open the Apche configuration file
  2. Find "#Include/private/etc/apache2/extra/httpd-vhosts.conf" in httpd.conf, remove the "#" from the front and save and exit.
  3. Run "sudo apachectl restart" and restart Apache to turn on its virtual host configuration feature.
  4. Run "sudo vi/etc/apache2/extra/httpd-vhosts.conf" to open the file httpd-vhost.conf that configures the virtual host and configure the virtual host you need. It is important to note that the file is enabled by default for two virtual hosts as an example: Xml/html code
    1. <VirtualHost *:80>
    2. ServerAdmin [email protected]
    3. DocumentRoot "/usr/docs/dummy-host.example.com"
    4. ServerName dummy-host.example.com
    5. Errorlog "/private/var/log/apache2/dummy-host.example.com-error_log"
    6. Customlog "/private/var/log/apache2/dummy-host.example.com-access_log" common
    7. </VirtualHost>
    8. <VirtualHost *:80>
    9. ServerAdmin [email protected]
    10. DocumentRoot "/usr/docs/dummy-host2.example.com"
    11. ServerName dummy-host2.example.com
    12. Errorlog "/private/var/log/apache2/dummy-host2.example.com-error_log"
    13. Customlog "/private/var/log/apache2/dummy-host2.example.com-access_log" common
    14. </VirtualHost>


    In fact, these two virtual hosts do not exist, and when no other virtual host is configured, it may result in the following prompt when accessing localhost:


    Forbidden you don ' t have permission to access/index.php on the This server


    The simplest way to do this is to add the # to the front of each line and comment it out, so that you can refer to it without causing other problems.


  5. Add the following configuration xml/html code
    1. <VirtualHost *:80>
    2. DocumentRoot "/users/[User name]/sites"
    3. ServerName Sites
    4. Errorlog "/private/var/log/apache2/sites-error_log"
    5. Customlog "/private/var/log/apache2/sites-access_log" common
    6. </VirtualHost>

    Save the exit and restart Apache.

  6. Run "sudo vi/etc/hosts", open the Hosts configuration file, add "127.0.0.1 sites", so you can configure the completion sites virtual host, so you can use "http://sites" access, its content and "http:// localhost/~[user Name] "is exactly the same.


This is a configuration implemented using the native support of Mac OS X 10.6.3, or "Mac OS X Leopard: Configuring Apache, PHP, SQLite, MySQL, and PhpMyAdmin (i)" and "Mac OS X leop ARD: Configure Apache, PHP, SQLite, MySQL, and PhpMyAdmin (ii) ". In fact, you can also use XAMPP or MacPorts as a third-party integration solution for simple installation and use.



--------
Worth a view



Original link: Uncle Fat



Configure Apache + PHP + MySQL in Mac OS x in detail


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.