Mac OS X is a UNIX-based operating system, and many of the software is integrated into the system. Therefore, the development environment for configuring PHP is simpler than Windows and Linux.
1. Start the Apache server
Open Terminal (terminal) to view Apache and PHP versions
$ apachectl -v && php -v
Server version: Apache/2.4.9 (Unix)
Server built: Sep 9 2014 14:48:20
PHP 5.5.14 (cli) (built: Sep 9 2014 19:09:25)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2014 Zend Technologies
To start the Apache server, the operation needs to switch the root user to avoid problems with sudo.
Note that the following actions are root-user operations, and sudo is required for each operation, if not the root user.
sudo su -apachectl start
Add:
Restart Apache Server
Apachectl restart
Close Apache Server
Apachectl stop
View version
httpd-vapachectl-v
Click on the http://localhost/link to see "It works! "The Apache server is successfully opened
2. Configure PHP
Go to the Apache directory to back up the httpd.conf file
cd/etc/apache2/CP httpd.conf Httpd.conf.bak
After backup, open the httpd.conf file with VI andLoadModule php5_module libexec/apache2/libphp5.so的remove the #
VI httpd.conf
#The following is the content of the httpd.conf file
#LoadModule rewrite_module libexec / apache2 / mod_rewrite.so
LoadModule php5_module libexec / apache2 / libphp5.so
#LoadModule hfs_apple_module libexec / apache2 / mod_hfs_apple.so
<IfModule unixd_module>
#The penultimate line in LoadModule
Restart Apache Server
Apachectl restart
View the default server root directory
grep " DocumentRoot " httpd.conf
The terminal displays the following content
Which"/library/webserver/documents"
Write info.php with VI
VI /library/webserver/documents/info.php
Enter in info.php
<? PHP Phpinfo ();? >
Open the http://localhost/info.php link to view PHP version information.
3. Install MySQL
Click http://dev.mysql.com/downloads/mysql/to select the MySQL dmg file in mac OS x, download, (http://dev.mysql.com/get/Downloads/ MYSQL-5.6/MYSQL-5.6.23-OSX10.9-X86_64.DMG)
Click Install after the download is complete, and then agree and continue until the installation is complete. When the installation is complete, open the MySQL server in System Preferences
After you turn on the MySQL server, as
The MySQL server can be started after the operation of the database, in Windows are accustomed to the command line to start MySQL, you can set the Mac terminal alias. Open terminal and enter the following command:
mysql= '/usr/local/mysql/bin/mysql '
Just installed MySQL root user is not set password, in order to secure after setting up the MySQL alias, after the terminal input MySQL, then will display the MySQL information.
At the command prompt, enter
123456
The password was modified successfully.
4. PHP Connection Database
Enter the following command at the terminal:
CD/mkdir mysqlcd mysqlln -s/tmp/mysql.sock mysql.sock
Otherwise, the warning will be reported.
Terminal Enter the following command:
VI /library/webserver/documents/dbconnect.php
In the new php file, enter:
<?php
$con = mysql_connect("localhost","root","123456");
var_dump($con);
if (!$con) {
die(‘Could not connect: ‘ . mysql_error());
}
else {
echo "connect success!";
}
// some code
?>
Open http://localhost/dbconnect.php to view the connection results.
5. Modify the root directory
The root directory is the directory location where files are shared from the file system, Mac OS X has two levels of Web root, System-level, and user-level. Personal local development can use the user-level root directory, so that less to have to maintain the root user's permission constraints, but also to modify the corresponding configuration.
The system-level root URL for Mac OS x is: http://localhost corresponding file directory/library/webserver/documents/
MAC OS x user-level root directory, the corresponding file share directory for ~/sites, this file directory to create their own, in the normal user's home (~) directory
First, create a Web root in your own document. The directory path I created is ", and then enter the following command in the terminal:
cd/etc/apache2/usersVI username.conf
In the newly created file, enter:
<Directory "/Users/NY/Sites/">
AllowOverride All
Options Indexes MultiViews FollowSymLinks
Require all granted
</Directory>
Set file Permissions again
chmod 644 username.conf
Open httpd.conf
VI /etc/apache2/httpd.conf
Load modules to ensure that the # before each line is deleted
LoadModule authn_core_module libexec / apache2 / mod_authn_core.so
(Line 6 of the module load)
LoadModule authz_host_module libexec / apache2 / mod_authz_host.so
(Line 7 of the module load)
LoadModule userdir_module libexec / apache2 / mod_userdir.so
(Fifth penultimate line of module loading)
Then, find the user home directories, delete the # before the Include
# User Home directoriesinclude/private/etc/apache2/extra/httpd-userdir.conf
Next open another file
VI /etc/apache2/extra/httpd-userdir.conf
Remove the comments before the following settings
Include/private/etc/apache2/users/*. conf
Restart the Apache server, then open http://localhost/~NY/after Setup to access my local sites Directory
Finally, enable redirection
VI /etc/apache2/httpd.conf
Line No. 258 change allowoverride none to allowoverride all
PHP Preliminary: Build Apache+php+mysql under Mac OS X Yosemite