Mac 更改Apache文件系统目录

本文介绍如何在Mac上配置Apache服务器的DocumentRoot路径,并解决配置后可能出现的403 Forbidden访问拒绝问题。通过修改httpd.conf文件及设置正确的文件权限,确保Apache能够正常提供Web服务。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

环境: 已配置好apache服务器
参考:
1.mac 中配置apache的DocumentRoot路径 出现403 Forbidden错误

2.apache修改默认目录后访问拒绝

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访问权限问题.

这里写图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值