Configuring Apache in Mac OS x

Source: Internet
Author: User

The version of Mac OS X I'm using is 10.8.2,mac comes with an Apache environment.

    1. Launch Apache
    2. Set up a virtual host

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:
    <VirtualHost*:80>ServerAdmin [email protected] documentroot "/usr/docs/" ServerName dummy-host.example. COM errorlog "/private/var/log/apache2/" Customlog "/private/var/log/apache2/ "Common</VirtualHost> <VirtualHost*:80>ServerAdmin [email protected] documentroot "/usr/docs/" ServerName Dummy-host2.exampl errorlog "/private/var/log/apache2/" Customlog "/private/var/log/apache2/ "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:
    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
    <VirtualHost*:80>documentroot "/library/webserver/documents" ServerName localhost errorlog "/private/var/log/apache2/localhos T-error_log "Customlog"/private/var/log/apache2/localhost-access_log "Common</VirtualHost> <VirtualHost*:80>documentroot "/users/snandy/work" ServerName mysites errorlog "/private/var/log/apache2/sites-error_log" Customlog "/private/var/log/apache2/sites-access_log" Common<Directory/>Options Indexes followsymlinks multiviews allowoverride None Order deny, allow to from all</Directory></VirtualHost>

  6. Save the exit and restart Apache.
  7. Run " sudo vi /etc/hosts ", open the Hosts profile, add " 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.
  8. 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.
sudo chown -R :_www /Library/WebServer # 递归给目录设置属主为`_www`sudo chmod -R g+r /Library/WebServer # 递归给目录写读权限sudo apachectl restart # 重启apache

Configuring Apache in Mac OS x

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: 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.