[MAC] Configure Apache server on mac

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

image-20211208163230302

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:

image-20211208163142124

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

image-20211208163419512

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

image-20211208163704677

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

image-20211208163909114

image-20211208165048568

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

image-20211208165454163

(**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)

image-20211208165826435

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

image-20211208165959556

image-20211208170125320

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

image-20211208170237979

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.

Guess you like

Origin blog.csdn.net/CeciliaXinn/article/details/121802946