Configure Apache in Mac OS X

Source: Internet
Author: User

My Mac OS X version is 10.8.2, and Mac comes with an Apache environment.

  1. Start Apache
  2. Set VM

 

Start Apache

Open terminal and enter sudo apachectl-V (you may need to enter machine secrets ). The Apache version is shown as follows:

 

Enter sudo apachectl start to start Apache. Open the address bar of safari and enter "http: // localhost". The content is "It works !" . It is located under "/Library (resource library)/webserver/documents/", which is the default root directory of Apache.

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

  1. Right-click finder under the dock, select "go to folder", and enter "/etc"
  2. Go to --- Under finder and enter/etc.
  3. You can enter "Open/etc" in terminal"

 

Set VM
  1. Run"sudo vi /etc/apache2/httpd.confOpen the Apche configuration file.
  2. In httpd. conf, find"#Include /private/etc/apache2/extra/httpd-vhosts.conf", Remove the previous"", Save and exit.
  3. Run"sudo apachectl restart", Restart Apache and then enable the VM configuration function.
  4. Run"sudo vi /etc/apache2/extra/httpd-vhosts.conf", Opened the configure virtual host file httpd-vhost.conf, configure the virtual host. Note that two virtual hosts are enabled for this file by default:
    <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. when no other virtual hosts are configured, the following prompt may appear when accessing localhost:

    ForbiddenYou don‘t have permission to access /index.php on this server

    The simplest way is to add # in front of each line and comment it out, so that it can be referenced without causing other problems.

  5. Add the following configuration
    <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 "/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                Allow from all      </Directory></VirtualHost> 

    Save and exit, and restart Apache.

  6. Run"sudo vi /etc/hosts", Open the hosts configuration file, and add"127.0.0.1 mysites", In this way, you can configure the sites virtual host and access" http: // mysites ". The content of Mac OS X and" http: // localhost /~ [User name] "is completely consistent.
  7. Note:ErrorLog "/private/var/log/apache2/sites-error_log"It can also be deleted, but it is a good habit to record logs. It can help us determine when a problem occurs. If the Log Code is retained, the path of the log file must exist. If you modify the Log Code that does not exist, Apache cannot be served and no error prompt is displayed. This is quite disgusting.

Address: http://www.cnblogs.com/snandy/archive/2012/11/13/2765381.html

Configure Apache in Mac OS X

Related Article

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.