Enable the Apache service
The Mac system comes with the Apache service, you just need to enable it. Open the terminal and enter the following command to start the Apache service.
sudo apachectl start
Open the browser and enter http://localhost in the address bar. If It Works appears, it means the Apache service is started successfully.
The default root directory of Apache’s website server is in the path below. Recommended: "PHP Tutorial"
/Library/WebServer/Documents
The page opened above is the source file accessed: /Library/WebServer/Documents/index.html.en
Configure PHP environment
Mac system also comes with its own PHP environment, just open it.
Edit file /etc/apache2/httpd.conf Find the following line, then remove the # comment in front, and save it.
LoadModule php*_module libexec/apache2/libphp*.so
Where * represents the PHP version on your machine.
Create a new file named phpinfo.php under /Library/WebServer/Documents, enter the following code in it, and save it.
<?phpphpinfo();?>
Open the browser and enter http://localhost/phpinfo.php in the address bar. If the following message pops up, it means that the PHP environment is configured successfully.
Done!
For more PHP related knowledge, please visit PHP Chinese website!
The above is the detailed content of Super simple tutorial on setting up a PHP environment on Mac. For more information, please follow other related articles on the PHP Chinese website!