Operating system: OS X 10.11.2
1. Start Apache
Open terminal (terminal), enter command: sudo apachectl-k start;
In the browser address bar, enter: http://localhost, display the following information, Apache Normal startup
Apache Related commands: Start: sudo apachectl start stop: sudo apachectl stop restart: sudo apachectl restart view version number: sudo apachectl-v
2. Add PHP Module
Enter command in terminal: sudo vi/etc/apache2/httpd.conf, open httpd.conf
Remove the comment ' # ' from the front of the PHP module and restart apache,php add success
3. Configure ' Mysites ' virtual machine
1. In the terminal input command: mkdir/users/your user name/sites, add this folder as the physical storage location for the ' mysites ' virtual machine.
2. Open the Httpd.config and remove the "# Include /private/etc/apache2/extra/httpd-vhosts.conf"前面的‘#‘。
3. Select DocumentRoot " /library/webserver/documents " <directory "/library/webserver/documents" > ...</directory> the contents, copy the contents to the bottom of it, modify the yellow area to "/users/your username/sites" and save the exit.
In the terminal input command: sudo vi/etc/apache2/extra/httpd-vhosts.conf, open httpd-vhosts.conf.
Note Two default virtual machines with ' # ' in front of each line
Next, add the following code, save the exit, restart Apache
# ' localhost ' virtual machine <virtualhost *:80> documentroot "/library/webserver/documents" ServerName localhost errorlog "/private/var/log/apache2/localhost-error_log" Customlog "/private/var/log/apache2/localhost-access_log" common </virtualhost># ' mysites ' virtual machine <virtualhost *:80> documentroot "/users/your user name/sites" ServerName mysites errorlog "/private/var/log/apache2/ Mysites-error_log " customlog"/private/var/log/apache2/mysites-access_log "Common </VirtualHost>
In Terminal input command: sudo vi/etc/hosts, add "127.0.0.1 mysites", Save exit
In the terminal input command: sudo vi/users/your username/sites/info.php, add "<?php echo phpinfo ();?>", Save exit
Enter http://mysites/info.php in the browser
This concludes, thank you for reading!
The turbid-Muddy canoe was written in 2016.1.12
Reference Document: Http://www.cnblogs.com/snandy/archive/2012/11/13/2765381.html
Configure PHP and virtual machines for your Mac's own Apache