The version of Mac OS X I'm using is 10.8.2,mac comes with an Apache environment.
Launch Apache
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:
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 to 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.
Run the "sudo apachectl restart" and restart Apache to turn on the virtual host Configuration feature.
Run "sudo vi/etc/apache2/extra/httpd-vhosts.conf", open the configuration virtual host file httpd-vhost.conf, configure the virtual host. It is important to note that the file is enabled by default for two virtual hosts as an example:
<virtualhost *:80>ServerAdmin [email protected]-host.example.com 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]-host2.example.com 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:
Forbidden
You 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
<VirtualHost*:80>documentroot "/library/webserver/documents" ServerName localhosterrorlog "/private/var/log/apache2/ Localhost-error_log "Customlog"/private/var/log/apache2/localhost-access_log "Common</VirtualHost><VirtualHost*:80>documentroot "/users/snandy/work" ServerName mysiteserrorlog "/private/var/log/apache2/sites-error_log" Customlog "/private/var/log/apache2/sites-access_log" Common<Directory/>Options Indexes followsymlinks multiviewsallowoverride noneorder deny,allowallow from All#require all granted in Apach The configuration syntax has been modified in the E-high version, so let's change to require all granted</Directory></VirtualHost>
Save the exit and restart Apache.
Run "sudo vi/etc/hosts", open the Hosts configuration file, add "127.0.0.1 mysites", so you can configure the completion sites virtual host, can access "http://mysites", before 10.8 mac OS The x version has exactly the same content as the "http://localhost/~[user name".
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.
Mac OS apahce adding virtual machines