The Mac version used is 10.10.1,MAC's own Apache environment
is divided into two parts:
1. Start Apache
2. Setting up a virtual host
Launch Apache
Open the terminal,
>>sudo Apachectl-v, if there is a machine password will need to enter the password.
>>sudo apachectl start, which starts Apache
Verify that Apache is turned on and enter "http://localhost" in the browser, such as "It works" on the page, which is the success. It is located under/library/webserver/documents.
The Apache installation directory is hidden by default in/etc/apache2,etc and can be viewed at the terminal input open/etc.
Set up a virtual host
>>sudo vi/etc/apache2/httpd.conf, open Apache configuration file
>> find "#include/private/etc/apache2/extra/httpd-vhosts.conf", remove "#", Save exit.
>>sudo apachectl Restart, restart Apache service, turn on virtual host configuration function
>>sudo vi/etc/apache2/extra/httpd-vhosts.conf, to open the configuration of the virtual host file httpd-vhosts.conf, it is important to note that the file has been opened by default two as an example of a virtual host
In fact, these two virtual hosts are nonexistent and may cause access to localhost when no other virtual host is configured: Forbidden,you don ' t has permission to access/index.php on this Server
The simplest way is to comment them out.
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/erao/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
Require All granted
</
Directory
>
</
VirtualHost
>
Note that the documentroot, need to write the hostname of the machine, but also to create a good work folder in advance.
Require all granted, otherwise no matter how access is 403.
Keep exiting and restart Apache service
>>sudo vi/etc/hosts, open the hosts configuration file, add "127.0.0.1 mysites", so you can configure sites virtual host, access to "http://mysites" can.
The error log is placed in the/private/var/log/apache2/sites-error_log.
Reference to: http://www.cnblogs.com/snandy/archive/2012/11/13/2765381.html#;
http://ylw6006.blog.51cto.com/470441/965119
Configuring Apache in Mac