proc_open() 失败并显示“权限被拒绝"

2022-01-13 00:00:00 centos php apache

我正在尝试使用 proc_open() 来执行程序并打印结果.但是,我不断收到权限被拒绝".已将脚本和可执行文件的 chmod 设置为 0777,但无济于事.

I'm trying to use proc_open() to execute a program and print the results. However, I keep getting 'Permission denied'. Have set chmod to 0777 for the script and executable, but to no avail.

ini_get('safe_mode') 为假.

可能出了什么问题?

我正在使用 CentOS、Apache 和 PHP 5.3.3.

I'm using CentOS, Apache and PHP 5.3.3.

推荐答案

我在相同的设置下遇到了这个问题,问题原来是 SELinux(默认情况下是打开的)阻止 httpd 执行我的外部程序.您可以通过以下方式将其置于许可模式,

I had this problem with an identical setup, and the problem turned out to be SELinux (which is on by default) preventing httpd from executing my external programs. You can put it in permissive mode via,

setenforce permissive

如果您遇到与我相同的问题,那么现在一切正常.这将持续到您重新启动.

If you're seeing the same problem I was, everything should now work. This will last until you reboot.

要使更改永久生效,请转到/etc/selinux/config,然后更改:

To make the change permanent, go to /etc/selinux/config, and change:

SELINUX=enforcing

SELINUX=permissive

好的,我找到了一种不需要关闭 SELinux 的方法.据我了解,问题在于 httpd 有自己的域,不能触及它之外的东西.因此,最简单的做法是将您的脚本/程序移动到/var/www 目录树中.

OK, I found a way to do this that doesn't require turning off SELinux. The problem, as I understand it, is that httpd has its own domain and can't touch things outside it. So, the simplest thing to do is to move your scripts/programs into the /var/www directory tree.

如果这不可行,您可以改为就地更改程序的上下文:

If that's not possible, you can instead change the context of your program in-place:

semanage fcontext -a -t httpd_sys_content_t "/path/to/program(/.*)?"

这基本上会说你的程序属于httpd.

which will basically say that your program belongs to httpd.

相关文章