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:
- Right-click Finder under the dock, select "Go to Folder" and enter "/etc"
- In the Finder-----Go to the folder and enter/etc
- You can enter "OPEN/ETC" in terminal
Set up a virtual host
- Run "" At Terminal
sudo vi /etc/apache2/httpd.conf
to open the Apche configuration file
- Find "" In httpd.conf
#Include /private/etc/apache2/extra/httpd-vhosts.conf
, remove the previous "" #
, save and exit.
- Run "
sudo apachectl restart
", after restarting Apache, the virtual Host Configuration feature is turned on.
- Run
sudo 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
- <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.
- Add the following configuration[HTML]View Plaincopy
- <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.
- 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.
- 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