无法从 PHP Fedora 10 调用系统命令和 shell 脚本
我正在开发一个通过 PHP 和 Apache 在 Fedora 10 机器上本地运行的应用程序。 这取决于在后台运行的进程。
上级希望能够通过浏览器启动/停止/重新启动该进程。 我试图通过让 PHP 使用 exec() 和 shell_exec 调用系统来使其工作,但它似乎不起作用。
当我尝试使用“exec('processName')”启动进程时,没有任何反应。
当我尝试使用“exec('killall processName')”时,SELinux 开始不断弹出警告,提示该进程已被允许(因为我将其置于许可模式),但它实际上并没有杀死该进程! 但即使页面完全加载后,这种情况似乎仍在继续!?!?
我能够以类似的方式调用另一个脚本:“exec('/var/www/cgi-bin/ControlProgram START')”。 所以我不太确定这两个调用/命令之间的主要区别是什么。
我还将脚本调用放入 /etc/rc.local 文件中,以便在登录时运行脚本。 但是,我能否从 PHP 中杀死该脚本,因为它是由系统运行的?
在权限/SELinux 方面,我不是专家,所以不要吝惜血淋淋的细节! 提前致谢!
I am working on an application that runs locally on a Fedora 10 machine through PHP and Apache. It depends on a process that runs in the background.
The higher-ups want to be able to start/stop/restart the process, through the browser. I was trying to get this to work by having PHP make calls to the system using exec() and shell_exec, but it doesn't seem to work.
When I try to start the process using "exec('processName')", nothing happens.
When I try to use "exec('killall processName')", SELinux starts constantly popping up warnings that the process was permitted (because I put it into permissive mode), however it doesn't actually kill the process! But this seems to go on even after the page is fully loaded!?!?
I AM able to call another script in a similar fashion: "exec('/var/www/cgi-bin/ControlProgram START')". So I'm not really sure what the major differences are between the two calls/commands.
I also put the script call into the /etc/rc.local file to have the script run at login. However, will I be able to kill this script from PHP since its run by... the system?
I'm not a guru when it comes to permissions/SELinux, so don't spare on the gory details! Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您对此系统有管理控制权,您将需要检查 PHP 配置(确保它是 Web 服务器的配置文件)。
Safe_Mode 将阻止 PHP 执行特定文件夹之外的任何内容。 在共享托管环境中,这通常意味着您只能执行与您的 home/www 文件夹相关的操作 - 根据您的笔记,这似乎是这种情况。
If you have administrative control over this system you will want to check the PHP configuration (make sure it is the config profile for the web server).
Safe_Mode will prevent PHP from executing anything outside a particular folder. In a shared hosting environment, this usually means you can only execute things that are relative to your home/www folder--which seems to be the case based on your notes.
我相信我发现了问题。 我仍然不确定问题是什么,但看起来它与文件/目录权限有关。 当我将脚本移动到 /var/www/html 目录时,脚本就会运行。 我将它们移到 /var/www/cgi-bin 中,它们也在那里工作。 因此,apache 可能无法执行 /var/www 目录之外的脚本,或者至少不能直接执行。 不过还是谢谢你的帮助!
I believe I found the problem. I'm still not exactly sure what the problem is, but it looks like it has something to do with file/directory permissions. When I moved the scripts into my /var/www/html directory, the scripts ran. I moved them into /var/www/cgi-bin and they work there too. So it might be something where apache can't execute scripts that are outside the /var/www directory, or at least it can't do it directly. Thanks for your help though!
这听起来像是老派的 UNIX 权限和 apache 的操作方式。 我确实记得(尽管已经有一段时间了)apache 对于执行的内容非常谨慎。 仔细检查你的八进制。
要验证它不是 SELinux,您可以禁用它而不是将其置于许可状态。 尽管这会导致文件系统重新标记(或应该)。 那时,您的 SELinux 上下文的扩展属性可能会失控,并在再次执行时导致 SELinux 问题。
It sounds like old school unix permissions and how apache operates. I do recall (though it has been some time) that apache is careful on what it will execute. Double check your octals.
To verify that it isn't SELinux you can disable it instead of putting it in permissive. though this will cause a file system relabel (or should). At that point your extended attributes with the SELinux contexts could get out of wack and cause SELinux problems once in enforcing again.