In Mac OS X, it's easy to enable the Apache service by turning on web sharing:
The Setup method is as follows:
Open Web share (Web sharing), System settings Preferences (Preferences), share (sharing), select to
Launch Apache
There are two ways of doing this:
- Open Web share (Web sharing), System settings Preferences (Preferences), sharing (sharing)
- Open terminal (terminal), then (note: sudo requires a password that is the root account password of the system)
- Run "
sudo apachectl start
", then enter the account password so that Apache runs.
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.
The system defaults to the current user's access directory is the form of http://localhost/~username, pointing to the user's home directory under the Sites directory. In many cases, we would like to have direct access to the root directory (http://localhost/) to directly access our own sites directory instead of the system default directory.
Make the following changes:
1. Open /etc/apache2/httpd.conf file
sudo vim/etc/apache2/httpd.conf
2. Find
/library/webserver/documents
Replaced by
/users/{username}/sites
where {username} is your login username, such as:
/users/liangc/sites
3. Restart the Web share (Web sharing) (remove the tick and select it again)
or run " sudo apachectl restart
"
Once the reboot is successful, you can use http://localhost/to directly access the contents of your sites directory without adding a username.
Thanks.
Click the icon mark for Star tag thing mac modify the default Apache site root location