MAMP configuration virtual host under Mac

For users using MAMP PRO, please ignore the following

First enter the Apache configuration file httpd.conf, the path is /Applications/MAMP/conf/apache/httpd.conf, open it with a text editor, command + f to find the 'vhosts' keyword, and come to this line

#Include /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf

Remove the preceding # sign to indicate that this sentence takes effect. The meaning of this sentence is to make the configuration file of the virtual address take effect.

After saving, open /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf with a text editor and add the virtual address that needs to be configured, probably like this:

<VirtualHost *: 80 > 
    DocumentRoot " / Applications / MAMP / htdocs / thinkphp5 / public " 
    ServerName tests.cn 
    ServerAlias ​​tests.cn
     <Directory " / Applications / MAMP / htdocs / thinkphp5 / public " > 
        Options Indexes FollowSymLinks    
        AllowOverride All 
        Order deny, allow 
        # Allow from all Note: If I add this sentence, I still report that the server cannot be accessed, so I used the following sentence: 
        Require all granted
  
     </ Directory> 
</ VirtualHost>

After saving, come to the host configuration file, / etc / hosts, you can enter the finder, shift + command + G, enter / etc, and press Enter to find the hosts file, open it with an editor, or directly enter sudo vi / etc in the terminal / hosts, then add a line of parsed statements

127.0.0.1 tests.cn

 

After saving, restart apache, and enter tests.cn in the browser, which is the virtual domain name you just set up. 

The above is the Apache configuration in MAMAP.

If you use the apache
httpd.conf that comes with the Mac : /etc/apache2/httpd.conf
httpd-vhosts.conf: / etc / apache2 / extra / /etc/vhosts.conf
hosts The location remains unchanged

Note: There are two cases of configuring virtual hosts in the /etc/apache2/extra/httpd-vhosts.conf file. If you
open the virtual host, you need to comment out these two cases with #, otherwise you will get an error when restarting apache

Apache default installation path is at /private/etc/apache2/ 
Apache terminal command: 
view version: sudo apachectl -v
start: sudo apachectl start
stop: sudo apachectl stop
restart: sudo apachectl restart



 

 

  

 

Guess you like

Origin www.cnblogs.com/ztshuai/p/12677637.html