Version: Apache2
Commands:
sudo apachectl start
sudo apachectl stop
sudo apachectl -k restart
相关文件夹Path
安装目录:/etc/apache2
默认放网页地址:/Library/WebServer/Documents
访问地址:http://localhost
自定义放网页地址:/Users/<your short user name>/Sites/
访问地址:http://localhost/~<your short user name>
增加自定义放网页的目录
创建目录
mkdir ~/Sites创建一个网页
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,作修改- 添加内容
<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
-
测试
- 默认放网页地址:
/Library/WebServer/Documents
访问地址:http://localhost
网页显示:
- 默认放网页地址:
It works!
1. 自定义放网页地址:```/Users/<your short user name>/Sites/```
访问地址:http://localhost/~<your short user name>
Note:注意不要忘了波浪号~
网页显示:
My site works!