Home>Article>Backend Development> Detailed process of configuring virtual host on Mac

Detailed process of configuring virtual host on Mac

little bottle
little bottle forward
2019-04-17 15:23:14 3508browse

1. Start Apache This article mainly talks about

Terminal input: sudo apachectl start

The installation directory of Apache is: /etc/apache2/, etc is hidden by default. There are three ways to view:

1. When the desktop is in Finder: shift command g, enter "/etc" (that is, the shortcut key for Finder-Go-Go to the folder)

2. Open the terminal :cd /etc

3. You can enter "open /etc"

in the terminal. 2. Set up the virtual host

1. Run "sudo vi /etc/apache2 in the terminal /httpd.conf", open the Apche configuration file

2. Find "#Include /private/etc/apache2/extra/httpd-vhosts.conf" in httpd.conf and remove the preceding "#" , save and exit.

3. Run "sudo apachectl restart" and restart Apache to enable the virtual host configuration function.

4. Run "sudo vi /etc/apache2/extra/httpd-vhosts.conf" to open the virtual host configuration file httpd-vhost.conf and configure the virtual host. It should be noted that this file opens two virtual hosts as examples by default

 ServerAdmin webmaster@dummy-host.example.com DocumentRoot "/usr/docs/dummy-host.example.com" ServerName dummy-host.example.com ErrorLog "/private/var/log/apache2/dummy-host.example.com-error_log" CustomLog "/private/var/log/apache2/dummy-host.example.com-access_log" common   ServerAdmin webmaster@dummy-host2.example.com DocumentRoot "/usr/docs/dummy-host2.example.com" ServerName dummy-host2.example.com ErrorLog "/private/var/log/apache2/dummy-host2.example.com-error_log" CustomLog "/private/var/log/apache2/dummy-host2.example.com-access_log" common 

. In fact, these two virtual hosts do not exist. When no other virtual hosts are configured, access may occur. The following prompt appears when localhost is used:
Forbidden
You don't have permission to access /index.php on this server

The easiest way is to add # in front of each line and comment them out That's great, so it can be used as a reference without causing other problems.

5. Add the following configuration to support localhost access and add virtual host access

 DocumentRoot "/Library/WebServer/Documents" ServerName localhost ErrorLog "/private/var/log/apache2/localhost-error_log" CustomLog "/private/var/log/apache2/localhost-access_log" common   DocumentRoot "/Library/WebServer/Documents" ServerName 虚拟主机地址 (如:www.test.com) ErrorLog "/private/var/log/apache2/test-error_log" CustomLog "/private/var/log/apache2/test-access_log" common  Options Indexes FollowSymLinks MultiViews AllowOverride None Order deny,allow Allow from all  

Save, exit, and restart Apache.

6. Run "sudo vi /etc/hosts", open the hosts configuration file, and add "127.0.0.1 www.test.com", so that the test virtual host can be configured.

Open the browser and enter: www.test.com

It works!

Configuration successful, consistent with localhost!

Recommended course:PHP video tutorial

The above is the detailed content of Detailed process of configuring virtual host on Mac. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:cnblogs.com. If there is any infringement, please contact admin@php.cn delete