如果它说的是:
access to /mySite denied (filesystem path
'/Users/myusername/Sites/mySite') because search permissions
are missing on a component of the path
那么你的文件权限有问题。您可以通过从终端运行以下命令来修复它们:
$ cd /Users/myusername/Sites/mySite
$ find . -type f -exec chmod 644 {} \;
$ find . -type d -exec chmod 755 {} \;
然后,刷新您的网站应位于的 URL(例如 http://localhost/mySite)。
如果您仍然收到 403 错误,并且您的 Apache error_log 仍然说同样的话,那么逐步向上移动您的目录树,并随时调整目录权限。您可以通过以下方式从终端执行此操作:
$ cd ..
$ chmod 755 mySite
如有必要,请继续:
$ cd ..
$ chmod Sites
如果有必要,
$ cd ..
$ chmod myusername
不要走得更远。你可能会彻底搞砸你的系统。
如果您仍然收到search permissions are missing on a component of the path 的错误消息,我不知道您应该怎么做。但是,我遇到了一个不同的错误(以下错误),我将其修复如下:
如果您的 error_log 说类似:
client denied by server configuration:
/Users/myusername/Sites/mySite
那么您的问题不在于您的文件权限,而在于您的 Apache 配置。
请注意,在您的httpd.conf 文件中,您将看到这样的默认配置(Apache 2.4+):
<Directory />
AllowOverride none
Require all denied
</Directory>
或像这样(Apache 2.2):
<Directory />
Order deny,allow
Deny from all
</Directory>
不要改变这个!我们不会在全局范围内覆盖这些权限,而是在您的 httpd-vhosts.conf 文件中覆盖。
但是,首先,请确保 httpd.conf 中的 vhost Include 行未注释。它应该看起来像这样。 (您的确切路径可能不同。)
# Virtual hosts
Include etc/extra/httpd-vhosts.conf
现在,打开您刚刚Included 的httpd-vhosts.conf 文件。如果您还没有,请为您的网页添加一个条目。它应该看起来像这样。 DocumentRoot 和 Directory 路径应该相同,并且应该指向您的 index.html 或 index.php 文件所在的位置。对我来说,它在 public 子目录中。
对于 Apache 2.2:
<VirtualHost *:80>
# ServerAdmin webmaster@dummy-host2.example.com
DocumentRoot "/Users/myusername/Sites/mySite/public"
ServerName mysite
# ErrorLog "logs/dummy-host2.example.com-error_log"
# CustomLog "logs/dummy-host2.example.com-access_log" common
<Directory "/Users/myusername/Sites/mySite/public">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
Allow from all
Require all granted
</Directory>
</VirtualHost>
台词
AllowOverride All
Require all granted
对于 Apache 2.4+ 至关重要。如果没有这些,您将不会覆盖httpd.conf 中指定的默认 Apache 设置。请注意,如果您使用的是 Apache 2.2,这些行应该改为
Order allow,deny
Allow from all
此更改一直是造成此问题的 google 用户(例如我)困惑的主要原因,因为复制粘贴这些 Apache 2.2 行在 Apache 2.4+ 中不起作用,而且 Apache 2.2 行仍然常见于旧帮助中线程。
保存更改后,重新启动 Apache。此命令将取决于您的操作系统和安装,因此如果您需要帮助,请单独搜索。