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:
- Launch Apache
- Running PHP
- Install MySQL
- Using phpMyAdmin
- Configuring PHP's MCrypt Extension library
- Set up a virtual host
Launch Apache
There are two ways of doing this:
- Open Web share (Web sharing), System settings Preferences (Preferences), sharing (sharing)
- Open terminal (terminal), then (note: sudo requires a password that is the root account password of the system)
- Run "sudo apachectl start" and enter your account password so that Apache runs.
- 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
- 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. )
- 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).
- 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
- Run "sudo apachectl restart" and restart Apache so PHP is ready to use.
- 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.
- 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.
- Download MySQL 5.1. Select the appropriate version, for example, MYSQL-5.1.46-OSX10.6-X86_64.DMG is selected here.
- 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.
- Click Install 2nd file mysqlstartupitem.pkg, so that MySQL will automatically start automatically when the boot.
- 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.
- 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.
- Download phpMyAdmin. Choose the right version, such as the one I chose is the phpmyadmin-3.3.2-all-languages.tar.bz2 version.
- Copy the Phpmyadmin-3.32-all-languages folder in "Download (downloads)" To "/users/[user name]/sites" with the name renamed phpMyAdmin.
- Copy the config.sample.inc.php in "/users/[User name]/sites/phpmyadmin/" and name it config.inc.php
- 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;
- 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:
-
- Download and unzip the libmcrypt-2.5.8.tar.bz2.
-
- Execute the following command at the terminal (note that the following commands are required to install Xcode support): xml/html code
- CD ~/downloads/libmcrypt-2.5.8/
- ./configure--disable-posix-threads--enable-static
- Make
- sudo make install
-
- 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.
-
- Execute the following command at the terminal: xml/html code
- CD ~/downloads/php-5.3.1/ext/mcrypt
- Phpize
- ./configure
- Make
- CD modules
- sudo cp mcrypt.so/usr/lib/php/extensions/no-debug-non-zts-20090626/
-
- 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
-
- Run "sudo vi/etc/apache2/httpd.conf" on the terminal to open the Apche configuration file
-
- Find "#Include/private/etc/apache2/extra/httpd-vhosts.conf" in httpd.conf, remove the "#" from the front and save and exit.
-
- Run "sudo apachectl restart" and restart Apache to turn on its virtual host configuration feature.
- 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
-
- <VirtualHost *:80>
-
- ServerAdmin [email protected]
-
- DocumentRoot "/usr/docs/dummy-host.example.com"
-
- ServerName dummy-host.example.com
-
- Errorlog "/private/var/log/apache2/dummy-host.example.com-error_log"
-
- Customlog "/private/var/log/apache2/dummy-host.example.com-access_log" common
-
- </VirtualHost>
-
- <VirtualHost *:80>
-
- ServerAdmin [email protected]
-
- DocumentRoot "/usr/docs/dummy-host2.example.com"
-
- ServerName dummy-host2.example.com
-
- Errorlog "/private/var/log/apache2/dummy-host2.example.com-error_log"
-
- Customlog "/private/var/log/apache2/dummy-host2.example.com-access_log" common
-
- </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.
-
- Add the following configuration xml/html code
- <VirtualHost *:80>
- DocumentRoot "/users/[User name]/sites"
- ServerName Sites
- Errorlog "/private/var/log/apache2/sites-error_log"
- Customlog "/private/var/log/apache2/sites-access_log" common
- </VirtualHost>
Save the exit and restart Apache.
-
- 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