article Songyang
This article is from the Asura road , prohibited for commercial purposes, reproduced please indicate the source.
http://blog.csdn.net/fansongy/article/details/ 43449337
/span>
/p>
Basic knowledge
Here are some basic settings for Apache reference this article
Open terminal (terminal), enter
sudo apachectl-v
Version of Apache can be displayed
Then enter sudo apachectl start
to launch Apache. 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 "sudo vi/etc/apache2/httpd.conf" on the terminal, open the Apche configuration file
- Find "#Include/private/etc/apache2/extra/httpd-vhosts.conf" in httpd.conf, remove the "#" from the front and save and exit.
- runs "sudo apachectl restart", and the virtual host Configuration feature is turned on after you restart Apache.
- runs "sudo vi/etc/apache2/extra/httpd-vhosts.conf", it opens the configuration virtual host file httpd-vhost.conf, configures the virtual host. It is important to note that the file opens two virtual hosts as an example 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 reality, these two virtual hosts do not exist, and when no other virtual host is configured, it may cause the following prompt when accessing localhost.
Forbiddenyou don ' t has permission to access/index.php on the 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
<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/fansy/sites" 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< C13/></directory></virtualhost>
Save the exit and restart Apache.
Run sudo vi /etc/hosts
, open the hosts configuration file, join 127.0.0.1 mysites
, so that you can configure the completion of the sites virtual host, can be accessed 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 case of problems 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.
Forbidden
After the above settings are still error:
Forbiddenyou don ' t has permission to access/on the this server.
The reason for the query is that the Yosemite permission policy has changed. Need to change some configuration, I refer to this article
The core is libphp5.so
to open and mod_userdir.so
load the two libraries, enabling the httpd-userdir.conf
configuration. Of course, we have just configured the virtual host is not delayed, can be used together.
MAC Yosemite Configuration Apache