Apache:0777 目录的权限被拒绝
Apache: Permission denied on 0777 directory
我有 shell 脚本,它是这样的:
#!/bin/bash
( cd /var/qwebirc; ls .git; )
和PHP执行脚本的文件:
error_reporting(E_ALL);
exec("/var/qwebirc/pull.sh 2>&1", $arr);
然后当我直接调用 shell 脚本时,我得到了我期望的输出 (ls of .git)。当我从 CLI 调用 PHP 脚本时,我得到了完全相同的输出。但是当从浏览器调用 php 脚本时,我得到
ls: cannot open directory .git: Permission denied
好吧,显然是apache用户的权限问题。所以我将 0777 设置为 .git 及其所有文件(用于测试目的)。 chown 和 chgrp 到 apache。将脚本更改为:
( cd /var/qwebirc; pwd; whoami; ls -dl .git; ls .git; )
但是浏览器中的输出仍然是:
[0] => /var/qwebirc
[1] => apache
[2] => drwxrwxrwx. 8 apache apache 4096 Mar 1 03:59 .git
[3] => ls: cannot open directory .git: Permission denied
这对我来说意义不大。知道有什么问题吗?谢谢。
所以答案是SELinux。不确定它的策略是如何工作的(现在得研究一下),但在禁用 SELinux 后,来自 apache 的 ls 开始工作。
我有 shell 脚本,它是这样的:
#!/bin/bash
( cd /var/qwebirc; ls .git; )
和PHP执行脚本的文件:
error_reporting(E_ALL);
exec("/var/qwebirc/pull.sh 2>&1", $arr);
然后当我直接调用 shell 脚本时,我得到了我期望的输出 (ls of .git)。当我从 CLI 调用 PHP 脚本时,我得到了完全相同的输出。但是当从浏览器调用 php 脚本时,我得到
ls: cannot open directory .git: Permission denied
好吧,显然是apache用户的权限问题。所以我将 0777 设置为 .git 及其所有文件(用于测试目的)。 chown 和 chgrp 到 apache。将脚本更改为:
( cd /var/qwebirc; pwd; whoami; ls -dl .git; ls .git; )
但是浏览器中的输出仍然是:
[0] => /var/qwebirc
[1] => apache
[2] => drwxrwxrwx. 8 apache apache 4096 Mar 1 03:59 .git
[3] => ls: cannot open directory .git: Permission denied
这对我来说意义不大。知道有什么问题吗?谢谢。
所以答案是SELinux。不确定它的策略是如何工作的(现在得研究一下),但在禁用 SELinux 后,来自 apache 的 ls 开始工作。