Mac Configuration Virtual Host

Source: Internet
Author: User

First, start Apache

Terminal input: sudo apachectl start

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

1. When the desktop is located in the Finder: shift+command+g, enter "/etc" (that is, finder--Go-to Folder shortcut keys)

2. Open Terminal: cd/etc

3. You can enter "OPEN/ETC" in terminal

Second, set up the virtual host

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

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

3. Run "sudo apachectl restart" to restart Apache and turn on the virtual host Configuration feature.

4. Run "sudo vi/etc/apache2/extra/httpd-vhosts.conf", open the configuration virtual host file httpd-vhost.conf, configure the virtual host. It is important to note that the file is enabled by default for two virtual hosts as an example

Code:

<VirtualHost*:80>ServerAdmin [email protected] 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</VirtualHost> <VirtualHost*:80>ServerAdmin [email protected] 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</VirtualHost> 

In fact, these two virtual hosts do not exist, and when no other virtual host is configured, it may result in the following prompt when accessing localhost:
Forbidden
You don't have permission to access/index.php on this server

The simplest way to do this is to add the # to the front of each line and comment it out, so that you can refer to it without causing other problems.

5. Add the following configuration to support localhost access, adding virtual host access

<VirtualHost*:80>documentroot "/library/webserver/documents" ServerName localhost errorlog "/private/var/log/apache2/ Localhost-error_log "Customlog"/private/var/log/apache2/localhost-access_log "Common</VirtualHost> <VirtualHost*:80>documentroot "/library/webserver/documents" ServerName Virtual host address (for example: www.test.com) errorlog "/private/var/log/ Apache2/test-error_log "Customlog"/private/var/log/apache2/test-access_log "Common<Directory/>Options Indexes followsymlinks multiviews allowoverride None Order deny,allow allow from all</Directory> </VirtualHost> 

Save, exit, restart Apache.

6. Run "sudo vi/etc/hosts", open the hosts profile, and add "127.0.0.1 www.test.com" so you can configure the test virtual host to complete.

Open Browser, type: www.test.com

It works!

Configuration successful, and localhost consistent!

Mac Configuration Virtual Host

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.