【问题标题】:Xampp & Apache: Alias 'access denied'Xampp & Apache:别名“访问被拒绝”
【发布时间】:2011-08-11 22:04:21
【问题描述】:

我刚刚在我的 Arch Linux 系统上安装了 Xampp。我现在想做什么:

我的 PHP 工作目录位于我的主文件夹中(位于 /home/luke/PHP)。我希望 Apache 访问这两个文件,所以我关注了 Arch Linux Wiki 上的 Xampp Installation guide 并为此目录创建了一个别名。 这就是我的 httpd.conf(别名部分)的样子:

Alias /PHP /home/luke/PHP
<directory /home/luke/PHP>
    AllowOverride FileInfo Limit Options Indexes
    Order allow,deny
    Allow from all
</directory>

之后,我将 home/luke/PHP 文件夹的权限更改为 777(使用 chmod)。当我尝试导航到 http://localhost/PHP

时,我重新启动了 Xampp 并得到了 403

Apache-Server 在 http-User(存在)和 http-Group 下运行。因此,我在我的组中添加了 http-User(我的用户的组 luke,使用 chown 工具)。我重新启动了服务器,同样的错误。

这是error_log文件的(一部分):

[Sun Apr 24 18:05:37 2011] [error] [client 127.0.0.1] (13)Keine Berechtigung: access to /PHP/ denied
[Sun Apr 24 18:10:30 2011] [error] [client 127.0.0.1] (13)Keine Berechtigung: access to /PHP/ denied
[Sun Apr 24 18:10:30 2011] [error] [client 127.0.0.1] (13)Keine Berechtigung: access to /PHP/ denied

所以,我创建的别名应该可以工作,但是我需要做什么才能让 Apache 服务器可以访问我的 /home/luke/PHP 文件夹?

我也尝试在 htdocs 文件夹中创建符号链接,但这也不起作用。

【问题讨论】:

    标签: linux apache permissions xampp alias


    【解决方案1】:

    Apache 需要能够:

    • 从您的 /home/luke/PHP 目录中读取 - 显然您已经允许这样做了
    • 遍历该目录的父目录。


    通常,您必须在您的主目录上将执行权限授予其他人(这意味着他们将能够遍历该目录,进入其子目录)

    chmod o+x /home/luke
    


    当然(尤其是在多用户环境中),然后您必须确保其他用户无法访问您的其他目录和文件——通常通过删除 group 和 @ 987654323@ 可能在您的主目录下的目录/文件上。

    【讨论】:

    • 我像你展示的那样更改了执行权限,但 Apache 仍然无法打开 PHP 文件夹中的文件。
    • @Lukas Knuth :您可能必须递归更改文件和目录的权限,例如: find /home/luke -type f chmod 644 {} \;查找 /home/luke -type d chmod 755 {} \;并确保它们属于 apache 用户。假设 apache 用户和组在您的 apache 配置文件中设置为“nobody”并且存在于您的系统中: chown -R nobody:nobody /home/luke
    • 很抱歉刚刚回到这个话题,但我在度假时没有我的机器;)。 Apache 在“http”-用户和组下运行。如果我更改我的“PHP”目录的所有者(使用 chown),我无法在其中写入文件。我想,将文件夹模式设置为 777,这样任何人都可以写入它会解决这个问题......
    • “遍历该目录的父目录”:这就是这个错误的线索。很难找到正确的答案。当然 chmod 必须是递归的!谢谢。
    【解决方案2】:

    我通过配置如上所示的别名解决了我的问题,但将 Apache 的用户设置为我的用户(“luke”)并将组排除在外:

    # User/Group: The name (or #number) of the user/group to run httpd as.
    # It is usually good practice to create a dedicated user and group for
    # running httpd, as with most system services.
    User luke
    #Group http
    

    之后,我将 htdocs- 和 PHP- 目录的所有者更改为我的用户 (luke) 并重新启动 LAMPP。

    现在一切正常。还要感谢 Pascal MARTIN 和 hornetbzz!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-04-02
      • 2018-08-10
      • 2017-01-15
      • 2016-06-26
      • 1970-01-01
      • 2016-09-18
      • 2017-08-11
      • 2014-05-23
      相关资源
      最近更新 更多