简体   繁体   English

PHP无法执行任何外部命令?

[英]php can't execute any external command?

We moved from Slackware to CentOS here, it was working fine then without notice, php stopped executing external calls such as calls to "wc" and "spamc". 我们从Slackware迁移到CentOS,它工作正常,然后没有通知,php停止执行外部调用,例如对“ wc”和“ spamc”的调用。 All such calls appear on error_log as: 所有此类调用在error_log上显示为:

sh: /usr/bin/spamc: Permission denied sh:/ usr / bin / spamc:权限被拒绝

The paths are correct. 路径正确。 We have the permissions set correctly and apache is supposed to be able to execute the files with no problem. 我们已经正确设置了权限,并且apache应该能够正常执行文件。 We're NOT on safe_mode and we do not have base_dir set. 我们也不是对的safe_mode和我们没有base_dir集。 It is not SELinux, or at least sestatus says SELinux is disabled. 它不是SELinux,或者至少sestatus说SELinux已禁用。

summary: 摘要:

  • PHP can't execute anything thru exec() or popen() PHP无法通过exec()或popen()执行任何操作
  • Paths to binaries are correct. 二进制文件的路径正确。
  • We are not in safe mode 我们不处于安全模式
  • We don't have base_dir set 我们没有设置base_dir
  • Permissions on the binaries allow apache user to execute them 二进制文件的权限允许apache用户执行它们
  • SELinux is disabled SELinux被禁用
  • disable_functions in php.ini is empty php.ini中的disable_functions为空
  • We have no clue why it doesn't work 我们不知道为什么它不起作用

PHP version 5.3.3 and CentOS 5.5 PHP版本5.3.3和CentOS 5.5

Anyone has a clue of what might be happening? 任何人都有可能发生的事情的线索吗? Thanks in advance 提前致谢

SELinux is blocking your attempts to run them. SELinux阻止了您尝试运行它们的尝试。 I recommend you come up with rules that allow you to run the subset of external commands required and load that as a module. 我建议您提出一些规则,使您可以运行所需的外部命令的子集并将其作为模块加载。

Found the error. 发现错误。

I was trying to execute /usr/bin/tidy for example, the usr folder had a 644 permission which is akin to lovecraftian horror in my book. 例如,我试图执行/ usr / bin / tidy,usr文件夹具有644权限,类似于我书中的lovecraftian恐怖。 I could work because I was root. 我可以工作,因为我是根。

I figured it out after going crazy and deciding to check the permissions on all the path components of the command from the root / folder to the tidy binary, I found all permissions set correctly but the usr folder perms were completely screwed. 我发了疯,决定检查从根目录/文件夹到整洁的二进制文件的所有路径组件的权限后,便找到了答案,我发现所有权限设置都正确,但usr文件夹的权限完全搞砸了。

This is fixed. 这是固定的。

Does PHP run as Apache on the server? PHP是否在服务器上作为Apache运行? I thought it ran as Nobody.. 我以为没有人跑。

https://serverfault.com/questions/207989/php-cant-execute-any-external-command/208001#208001 https://serverfault.com/questions/207989/php-cant-execute-any-external-command/208001#208001

Generally PHP on centOS is ran as nobody unless you have compiled php as fastcgi, dso etc... 通常,除非您将php编译为fastcgi,dso等,否则centOS上的PHP会以无人运行的方式运行...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM