经研究,只需要修改三个文件
1.编辑/etc/apache2/httpd.conf文件
a.
去掉 177行
'#LoadModule php7_module libexec/apache2/libphp7.so'
前面的#号
b.
去掉 517行
'#Include /private/etc/apache2/extra/httpd-vhosts.conf'
前面的#号
2.编辑/etc/apache2/extra/httpd-vhosts.conf文件
添加以下配置
'#配置localhost 防止配置了其他域名localhost无法使用'
<VirtualHost *:80>
ServerAdmin webmaster@dummy-host2.example.com
DocumentRoot "/Library/WebServer/Documents"
ServerName localhost
ErrorLog "/private/var/log/apache2/dummy-host2.example.com-error_log"
CustomLog "/private/var/log/apache2/dummy-host2.example.com-access_log" common
<Directory /Library/WebServer/Documents>
Require all granted
</Directory>
</VirtualHost>
'#配置ceshi.cn'
<VirtualHost *:80>
ServerAdmin webmaster@dummy-host2.example.com
DocumentRoot "/Users/xxx/WebServer"
ServerName ceshi.cn
ErrorLog "/private/var/log/apache2/dummy-host2.example.com-error_log"
CustomLog "/private/var/log/apache2/dummy-host2.example.com-access_log" common
<Directory /Users/xxx/WebServer>
Require all granted
</Directory>
</VirtualHost>
3.编辑/etc/hosts文件
添加一行
127.0.0.1 ceshi.cn
注意:修改以上配置要 sudo apachectl restart重启
如果发现浏览器输入ceshi.cn出现 403 Forbidden,很有可能/Users/xxx/WebServer文件夹下没有index.html