我有 shell 脚本,它是这样的:
#!/bin/bash
( cd /var/qwebirc; ls .git; )
执行脚本的 PHP 文件:
error_reporting(E_ALL);
exec("/var/qwebirc/pull.sh 2>&1", $arr);
然后当我直接调用 shell 脚本时,我得到了我期望的输出(.git 的 ls)。当我从 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 开始工作。
关于php - Apache:0777 目录的权限被拒绝,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28792799/