I. Overview
The Mac system is very friendly to the running of PHP. We only need to make a simple configuration to start using it. This article briefly introduces the installation and configuration of Apache and PHP, paving the way for the upcoming development.
2. Apache
1. Start the Apache service
The Apache service has been installed in the Mac system, we only need to start it in the following way to use it directly
Enter the following command in the terminal to start the Apache service
sudo apachectl start
Note: Because sudo is a system management command, you need to enter the computer password (it will not be displayed when entering characters, just press Enter after entering)
Enter the following command in the terminal to view the Apache service version
sudo apachectl -v
The version information in this machine is as follows
Server version: Apache/2.4.34 (Unix)
Server built: Feb 22 2019 19:30:04
Enter the following URL in the browser to check whether the Apache service is started successfully
http://localhost
or
http://127.0.0.1
If the Apache service starts successfully, the page will displayIt works!
2. Other Apache configurations
Shut down the Apache service
Enter the following command in the terminal to shut down the Apache service
sudo apachectl stop
Restart the Apache service
Enter the following command in the terminal to restart the Apache service
sudo apachectl restart
Apache service port number
The Apache service port number is 80 by default. If you want to modify the port number, you can /private/etc/apache2
find and open httpd.conf
the file in the directory, search for Listen 80
and modify the port number
Note: At this time, the apache service is only enabled, and the php file support is not enabled. Next, we will introduce how to enable apache to support the parsing of PHP files
3. PHP
1. Start PHP
The startup of PHP only needs to be configured in the Apache service and can be used directly:
First, in the Finder, use the shortcut keys command + shift + G to open 前往文件夹
the input box, /private/etc/apache2
after entering , click 前往
to go to the installation path of the Apache service, find httpd.conf
the file, and open it with a code editor;
Secondly, search #LoadModule php7_module libexec/apache2/libphp7.so
and delete the previous one #
.
Note: If you cannot modify it due to permission issues:
- Drag it to the desktop to modify, then delete the original one, and then drag the desktop one into it to be ok
Again, restart the Apache service
2. Find the root directory
At this time, find the root directory of the website specified by apache /Library/WebServer/Documents
, and create a new test.php program in this directory to try the effect.
<?php
echo "hello MAC";
?>
Enter the following URL in the browser to view the input information of PHP
http://localhost/test.php
Note: Administrator privileges are required to read the Document folder, it is recommended to modify the root directory
- In Finder, use the shortcut keys command + shift + G to open
前往文件夹
the input box, enter/private/etc/apache2
and click前往
to go to the installation path of the Apache service, findhttpd.conf
the file, and open it with a code editor; - Search
DocumentRoot
, as shown in the figure below:
- Just change the path part to the specified folder.
Then you can use webServer normally to start website development. If you need to use mysql, please see the next document.
If there is any incompleteness or error in the text, please leave a message to point out, thank you for your support... ^ _ ^