Launch Apache
There are two ways of doing this:
- Open Web share (Web sharing), System settings Preferences (Preferences), sharing (sharing)
- Open terminal (terminal), and then
- Run "sudo apachectl start" and enter your account password so that Apache runs.
- Run "sudo apachectl-v" and you will see the Apache version number in Mac OS X 10.6.3:
Server version:apache/2.2.14 (Unix) server built: Feb 11 2010 14:40:31
This allows you to enter "http://localhost" in the browser, and you can see that a content "It works!" appears Page, which is located under "/library (Resource Library)/webserver/documents/", which is the default root directory for Apache.
NOTE: When Apache is turned on, "web sharing" is turned on, and the networked user accesses the "/library (library)/webserver/documents/" directory via "http://[local ip]/", via "http://[local IP" /~[user Name] "To access the/users/[user name]/sites/directory, you can disable this access by setting the" Firewall (Firewall) "in" Security "in System preferences.
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 "sudo apachectl restart" and restart Apache to turn on its virtual host configuration feature.
- run sudo vi/etc/apache2/extra/httpd-vhosts.conf, which opens the file httpd-vhost.conf that configures the virtual host and configures the virtual host you need. It is important to note that the file opens by default two virtual hosts as an example:
<virtualhost *:80>serveradmin [Email protected]documentroot]/usr/docs/ Dummy-host.example.com "ServerName Dummy-host.example.comerrorlog"/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.comerrorlog"/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 you do not configure any other virtual hosts, you may get the following hint when you access localhost:
forbiddenyou Don ' t has permission to access/index.php the easiest way to do this server
is to add # to each line before they are commented out, so that you can refer to it without causing other problems.
- Add the following configuration
Save the exit and restart Apache.
- Run "sudo vi/etc/hosts", open the Hosts configuration file, add "127.0.0.1 sites", so you can configure the completion sites virtual host, so you can use "http://sites" access, its content and "http:// localhost/~[user Name] "is exactly the same.
This is a configuration implemented using the native support of Mac OS X 10.6.3, and can also refer to "" and "". In fact, you can also use XAMPP or MacPorts as a third-party integration solution for simple installation and use.
Configuring Apache in Mac OS X