【发布时间】:2021-02-07 21:14:43
【问题描述】:
总的来说,我对 PHP 和 Web 开发有点陌生,我正在尝试从 php.ini 执行一个程序。我设置了我的虚拟机并正确托管它,但是当网站尝试加载页面时,它说程序无法执行:“权限被拒绝”。我尝试了所有方法,包括:
- 为 /var/www/html 中的每个文件添加执行权限
- setfacl -m u:apache:rwx /var/www/
- chown -R apache:apache /var/www/
进一步的背景:
- 我在 fedora linux 上
这里是 index.php:
<html>
<body> <p>
<?php
exec("whoami && ./program 2>&1", $out);
foreach ($out as $element) {
echo $element;
echo "<br>";
}
?>
</p>
</body>
</html>
[fedora@fedora html]$ curl localhost
<html>
<body>
<p>
apache<br>sh: ./program: Permission denied<br></p>
</body>
</html>
互联网上的大多数提示都告诉您确保用户“apache”有权执行该文件。我已经做到了,并通过执行以下命令进行了验证。
[fedora@fedora html]$ sudo -u apache bash
bash-5.0$ ls -la
total 48
drwxrwxrwx. 2 apache apache 4096 Oct 25 11:22 .
drwxrwxrwx+ 4 apache apache 4096 Oct 25 09:51 ..
-rw-rw-rw-. 1 apache apache 158 Oct 25 11:04 index.php
-rwxrwxrwx+ 1 apache apache 20648 Oct 25 10:02 program
-rwxr-xr-x. 1 apache apache 23 Oct 25 10:57 p.sh
bash-5.0$ ./program
test
test
test
test
test
test
test
test
test
bash-5.0$ php index.php
<html>
<body>
<p>
apache<br>test<br>test<br>test<br>test<br>test<br>test<br>test<br>test<br>test<br>test<br>test<br>test<br>test<br>test<br>test<br>test<br>test<br>test<br>test<br>test<br>test<br>test<br>test<br></p>
</body>
</html>
bash-5.0$
我 sudo 进入了 apache 用户,并且能够读取目录中的每个文件并通过 shell 执行它们。之后,我运行了 php index.php,它完美地执行了脚本,并得到了 exepcted 的输出。
我完全不知道为什么它不能在浏览器中执行这个脚本,任何帮助将不胜感激!
编辑: 我检查了我的 php.ini 文件,没有禁用的功能
...
disable_functions =
...
【问题讨论】: