环境: 已配置好apache服务器
参考:
1.mac 中配置apache的DocumentRoot路径 出现403 Forbidden错误
1.在终端中打开etc/apache2/httpd.conf文件
$ cd etc/apache2
$ sudo vim httpd.conf
{输入密码}
vim编辑
$ i
2.修改DocumentRoot设置
DocumentRoot "/Library/WebServer/Documents"
<Directory "/Library/WebServer/Documents">
#
# Possible values for the Options directive are "None", "All",
# or any combination of:
# Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
#
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
#
# The Options directive is both complicated and important. Please see
# http://httpd.apache.org/docs/2.4/mod/core.html#options
# for more information.
#
Options FollowSymLinks Multiviews
MultiviewsMatch Any
#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# AllowOverride FileInfo AuthConfig Limit
#
AllowOverride None
#
# Controls who can get stuff from this server.
#
Require all granted
</Directory>
修改为
DocumentRoot "/Users/apple/Desktop/WebServerDocuments"
<Directory "/Users/apple/Desktop/WebServerDocuments">
#
# Possible values for the Options directive are "None", "All",
# or any combination of:
# Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
#
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
#
# The Options directive is both complicated and important. Please see
# http://httpd.apache.org/docs/2.4/mod/core.html#options
# for more information.
#
Options FollowSymLinks Multiviews
MultiviewsMatch Any
#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# AllowOverride FileInfo AuthConfig Limit
#
AllowOverride None
#
# Controls who can get stuff from this server.
#
Require all granted
</Directory>
键盘点击esc回到vim命令状态,输入
:wq
进行保存退出.
3.给新的目录开放访问权限
$ chmod 755 /Users/apple/Desktop/WebServerDocuments
重启Apache
$ sudo apachectl restart
可在WebServerDocuments中放入.php或.html文件测试:
完成, 注意如果缺少第三步,访问页面资源的时候会报403访问权限问题.