Configure Apache server on mac
Reference article:
https://blog.csdn.net/wanxue0804/article/details/79434058
1. Start Apache:
terminal:
//开启apache: sudo apachectl start
//重启apache: sudo apachectl restart
//关闭apache: sudo apachectl stop
Press Enter and you will be prompted to enter the password, which is the password of your computer.
http://127.0.0.1/Test it, success:
Two, configuration
1. First, create a sites folder under the folder of your computer nickname
Just put some fake data in the background.
Mine is version 10.13.2, remember that the folder should be placed under the User folder, otherwise it seems to fail. The location of the new version is Macintosh HD > User > your computer name
2. Find the configuration file and back up the original file
The next step is to enter the following command in the terminal (the code behind $ can be copied directly)
// switch working directory
$cd /etc/apache2
// Backup files, in case of accidents, only need to be executed once
$sudo cp httpd.conf httpd.conf.bak
3. Start modifying the configuration file
// Edit httpd.conf with vim
$sudo vim httpd.conf
// Find the DocumentRoot
/DocumentRoot
Press i to enter edit mode
You can see that there are two paths and change them to the path of the Sites folder you just created
attach vim
[yy] Copy the line where the cursor is located
[nyy] Copy the next n lines where the cursor is located
[p, P] p means to paste the copied data on the line below the cursor; P means to paste the copied data on the line above the cursor
[/word] Find the character string whose content is word in the file (downward search)
Scroll forward one screen: Ctrl+F
Scroll back one screen: Ctrl+B
【u】Undo the last operation
Then look for php
/php
After positioning this line, delete the # at the front of this line
(**If it is a system above 10.10, there is one more step: **Find Options input
/Options
You can also visually find the position in the picture, and add a word between Options and Follow)
After making a change, first press the esc key to exit the editing mode, and then enter: wq to save and exit. If you make a mistake and don’t want to save it, just: q!
4. Finishing work and confirmation of success
// switch to working directory
$cd /etc
//copy configuration file
$sudo cp php.ini.default php.ini
// After restarting the apache server, it is normal to say this sentence below
$sudo apachectl -k restart
It's normal to say this next time, don't worry
Then confirm whether it is successful or not, then enter localhost in the browser and if you can come to the following interface, it will be right
5. Precautions
Note the previous backup. Don't make multiple backups.
Note that all English symbols and letters are used under vim editing
If you want to use the server every time you turn it off and on, you have to type in the command to start it again.