Version: Apache2
Commands:
sudo apachectl start
sudo apachectl stop
sudo apachectl -k restart
相關(guān)文件夾Path
安裝目錄:/etc/apache2
默認(rèn)放網(wǎng)頁地址:/Library/WebServer/Documents
訪問地址:http://localhost
自定義放網(wǎng)頁地址:/Users/<your short user name>/Sites/
訪問地址:http://localhost/~<your short user name>
增加自定義放網(wǎng)頁的目錄
創(chuàng)建目錄
mkdir ~/Sites創(chuàng)建一個(gè)網(wǎng)頁
echo "<html><body><h1>My site works!</h1></body></html>" > ~/Sites/index.html.en
-
打開配置文件
sudo vi /etc/apache2/httpd.conf,做修改Uncomment the following line:
#LoadModule php5_module libexec/apache2/libphp5.so
to
LoadModule php5_module libexec/apache2/libphp5.soUncomment the following line:
#LoadModule userdir_module libexec/apache2/mod_userdir.so
to
LoadModule userdir_module libexec/apache2/mod_userdir.soUncomment the following line:
#Include /private/etc/apache2/extra/httpd-userdir.conf
to
Include /private/etc/apache2/extra/httpd-userdir.conf保存文件
/etc/apache2/httpd.conf
-
打開配置文件
sudo vi /etc/apache2/extra/httpd-userdir.conf,作修改uncomment the following line:
#Include /private/etc/apache2/users/*.conf
to
Include /private/etc/apache2/users/*.conf保存文件
/etc/apache2/extra/httpd-userdir.conf
-
打開配置文件
sudo vi /etc/apache2/users/<your short user name>.conf,作修改- 添加內(nèi)容
<Directory "/Users/<your short user name>/Sites/"> Options Indexes MultiViews AllowOverride None Order allow,deny Allow from localhost Require all granted </Directory>- 保存文件
/etc/apache2/users/<your short user name>.conf
-
測(cè)試
- 默認(rèn)放網(wǎng)頁地址:
/Library/WebServer/Documents
訪問地址:http://localhost
網(wǎng)頁顯示:
- 默認(rèn)放網(wǎng)頁地址:
It works!
1. 自定義放網(wǎng)頁地址:```/Users/<your short user name>/Sites/```
訪問地址:http://localhost/~<your short user name>
Note:注意不要忘了波浪號(hào)~
網(wǎng)頁顯示:
My site works!