Configuring Apache under Mac

1. Open a terminal and start Apache:

1.Mac already comes with Apache: we only need to enter the following commands in the terminal to complete: open, restart, close operations

//开启apache:  sudo apachectl start

//重启apache:  sudo apachectl restart

//关闭apache:  sudo apachectl stop

2. Verify that Apache is successfully enabled: Enter 127.0.0.1 or localhost in the browser , and the following output is displayed, even if it is successful


3. The address of the Apache server:

/Library/WebServer/Documents We can open the folder and press Command+Shift+G to enter the file path to quickly locate the server folder, "It works!" is in index.html.en

Second, customize the Apache address configuration

1. Check if there is a {username}.conf file under /etc/apache2/users. If you don't create a new one, don't forget to chmod to modify the vague permissions, otherwise you can't edit the content , enter the content and save it

<Directory "/Users/user name of the computer/manually create a folder name at will/">
    Options Indexes MultiViews
    AllowOverride All
    Order allow, deny
    Allow from all
</Directory>


2. Create a file index.php in a manually created folder. The content of the file is

<?php   
    echo "sss";
    echo phpinfo();
 ?>

3. Find the following two sentences in the httpd.conf file under /etc/apache2 and remove the preceding # sign

LoadModule php5_module libexec/apache2/libphp5.so

LoadModule userdir_module libexec/apache2/mod_userdir.so


4. Enter http://localhost/~luoyaosheng/, luoyaosheng is my username, change it to your username. Jump out of the following page and succeed



5. If you want to enter http://localhost to access the custom server address, you need to change the default address to the address you set in the httpd.conf file under /etc/apache2

#DocumentRoot "/Library/WebServer/Documents"
DocumentRoot "/Users/luoyaosheng/Sites"
#<Directory "/Library/WebServer/Documents">
<Directory "/Users/luoyaosheng/Sites">
It is recommended not to delete it directly, just comment out the # sign.

But please note: At this time, if you restart the Apache service, you will usually encounter a 403 permission error, because we need to modify some other configuration items.

There are mainly two aspects of the modification, you can also refer to my configuration

<Directory />
   Options Indexes FollowSymLinks
   AllowOverride None
   Order deny,allow
   Allow from all
</Directory>
#DocumentRoot "/Library/WebServer/Documents"
DocumentRoot "/Users/luoyaosheng/Sites"
#<Directory "/Library/WebServer/Documents">
<Directory "/Users/luoyaosheng/Sites">
    Options FollowSymLinks Multiviews
    Options Indexes FollowSymLinks
    MultiviewsMatch Any
    Require all granted
</Directory>

6. Enter sudo apachectl restart to restart apache 

Open the web page and enter http://localhost/index.php and call it a day

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325518369&siteId=291194637