php - Apache:0777 目录的权限被拒绝

标签 php linux apache shell

我有 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/

相关文章:

Linux,如何使用目录名创建文件?

python - 登录 mod_python/apache

python - 配置 Apache,以便子文件夹不由 WSGI 处理,而是由 Apache 本身处理

未找到 PHP 类 DateTime

php - 对来自 MySql 的记录进行分组

php - 在 PHP/Postgresql WHILE 循环中设置基于数据库字段的条件

php - 另一个表中的用户选项: what is the best practice to check if an option is there?

c++ - 如何检查显示器是否已插入? (Linux)

node.js - Ubuntu create-react-app 失败,权限被拒绝

apache - 电子标签配置错误