Mac install Apache Configure virtual Host

Source: Internet
Author: User

Source: http://blog.csdn.net/qianling3439/article/details/29410381

Launch Apache

Open terminal (terminal), enter sudo apachectl-v, (you may need to enter the machine secret). The Apache version is shown below

Then enter sudo apachectl start so that Apache starts up. Open Safari Browser address bar Enter "http://localhost", you can see the content "It works!" The page. It is located under/library (Resource Library)/webserver/documents/, which is the default root directory for Apache.

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

    1. Right-click Finder under the dock, select "Go to Folder" and enter "/etc"
    2. In the Finder-----Go to the folder and enter/etc
    3. You can enter "OPEN/ETC" in terminal

Set up a virtual host
  1. Run "" At Terminal sudo vi /etc/apache2/httpd.conf to open the Apche configuration file
  2. Find "" In httpd.conf #Include /private/etc/apache2/extra/httpd-vhosts.conf , remove the previous "" , save and exit.
  3. Run " sudo apachectl restart ", after restarting Apache, the virtual Host Configuration feature is turned on.
  4. Runsudo vi /etc/apache2/extra/httpd-vhosts.conf, the configuration virtual host file httpd-vhost.conf is turned on, and the virtual host is configured. It is important to note that the file is enabled by default for two virtual hosts as an example:[HTML]View Plaincopy
    1. <VirtualHost *:80>
    2. ServerAdmin [email protected]
    3. DocumentRoot "/usr/docs/dummy-host.example.com"
    4. ServerName dummy-host.example.com
    5. Errorlog "/private/var/log/apache2/dummy-host.example.com-error_log"
    6. Customlog "/private/var/log/apache2/dummy-host.example.com-access_log" common
    7. </VirtualHost>
    8. <VirtualHost *:80>
    9. ServerAdmin [email protected]
    10. DocumentRoot "/usr/docs/dummy-host2.example.com"
    11. ServerName dummy-host2.example.com
    12. Errorlog "/private/var/log/apache2/dummy-host2.example.com-error_log"
    13. Customlog "/private/var/log/apache2/dummy-host2.example.com-access_log" common
    14. </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:

    ForbiddenYou 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[HTML]View Plaincopy
    1. <VirtualHost *:80>
    2. DocumentRoot "/library/webserver/documents"
    3. ServerName localhost
    4. Errorlog "/private/var/log/apache2/localhost-error_log"
    5. Customlog "/private/var/log/apache2/localhost-access_log" common
    6. </VirtualHost>
    7. <VirtualHost *:80>
    8. DocumentRoot "/users/snandy/work"
    9. ServerName mysites
    10. Errorlog "/private/var/log/apache2/sites-error_log"
    11. Customlog "/private/var/log/apache2/sites-access_log" common
    12. <Directory />
    13. Options Indexes followsymlinks MultiViews
    14. AllowOverride None
    15. Order Deny,allow
    16. Allow from all
    17. </Directory>
    18. </VirtualHost>

    Save the exit and restart Apache.

  6. Run " sudo vi /etc/hosts ", open the Hosts profile, add " 127.0.0.1 mysites ", so you can configure the completion of the sites virtual host, you can access "Http://mysites", before 10.8 mac OS x version of its content and "http://localhost /~[user Name] "is exactly the same.
  7. Note that the log " ErrorLog "/private/var/log/apache2/sites-error_log" " can also be deleted, but logging is actually a good habit, in the event of a problem can help us to judge. If you keep these log code, a certain log file path is present, if you arbitrarily modify a non-existent, will cause Apache can not service without error prompts, this is more disgusting.

Mac install Apache Configure 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.