System overview
1. Start Apache (it has been integrated by default in mac, just start the service directly)
Open the terminal and enter:
Open the browser and enter:
should be fine See the "It works!" page, which is located in the /Library/WebServer/Documents/ directory, which is the default root directory of Apache (you can change it to your own directory, or create a virtual directory).
2. Open php
Input in the terminal:
cd
/etc/apache2/
sudo
vi httpd.conf
In vi, enter /php to search for text containing php and find:
#LoadModule
php5_module libexec/apache2/libphp5.so
Delete the # in front, then save and exit. (Press shift+i to enter at the beginning of the line, press ESC to exit editing, press
/etc
sudo
cp php.ini.
default
php.ini
sudo
apachectl restart
3. Test php
vi
index.php
Then enter the following content in info.php:
<html><body><h1>HelloWorld!h1>php phpinfo(); ?>body>html>Enter in the browser:
127.0.0.1 and HelloWord and php information will appear
4. Common errors
a. Due to modification The wrong httpd.conf cannot open 127.0.0.1. First check the hosts file;
b. After confirming that there is no problem, find httpd.conf~previous in the current directory and replace it, or find a colleague to send a copy of httpd to overwrite it. That’s it.
c. The test php file does not execute the php script: the test file suffix name .html is changed to .php
Copyright statement: This article is an original article by the blogger and may not be reproduced without the permission of the blogger.
The above has introduced the configuration of Apache + PHP in Mac OS