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:

    1

    2

    3

    4

    5

    6

    7

    8

    9

    10

    11

    12

    13

    14

    15

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

    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

    1

    2

    3

    4

    5

    6

    7

    8

    9

    10

    11

    12

    13

    14

    15

    16

    17

    18

    19

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

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