简体   繁体   English

从浏览器调用PHP脚本失败但从CLI调用失败

[英]PHP script fails when called from a browser but not from CLI

This is driving me nuts. 这让我疯了。

I've reduced my problem to this: I have a simple file 'test.php' that invokes a php file (this is from a bigger application, so in fact we need to execute many php scripts from a main script): 我把问题简化为:我有一个简单的文件'test.php'来调用一个php文件(这是来自一个更大的应用程序,所以实际上我们需要从主脚本执行许多php脚本):

<?php

 exec("php /var/www/setActive.php 273 1 2>&1",$arO,$nO);
echo $nO.'|'.implode(',',$arO);

The original path for setActive.php is way longer, I shortened it for this example. setActive.php的原始路径更长,我为此示例缩短了它。

Now, if I try: 现在,如果我尝试:

[root@stg]# sudo -u apache php test.php

I get: 我明白了:

0|

Great, this means the setActive.php script ran smoothly. 太棒了,这意味着setActive.php脚本运行顺畅。

Now, if I try it from a browser or from curl: 现在,如果我从浏览器或curl尝试它:

[root@stg]#curl http://my.url/path/test.php

This is what I get: 这就是我得到的:

1|Could not open input file: /var/www/setActive.php

I already reviewed all the permissions. 我已经查看了所有权限。 Apache user has access to all directories and files. Apache用户可以访问所有目录和文件。 This was working ok in another server. 这在另一台服务器上工作正常。 I reviewed the php.ini files and there is no difference between them. 我查看了php.ini文件,它们之间没有区别。

Maybe is a option that I'm not seeing, or an apache config option. 也许是我没有看到的选项,或者是apache配置选项。 I'm ran out of ideas. 我的想法用完了。

Please help me! 请帮我!

Thanks in advance. 提前致谢。

I have Linux, Cent OS. 我有Linux,Cent OS。 PHP 5.3.23 PHP 5.3.23

If permissions etc.. are all ok, possibly the apache config. 如果权限等..都可以,可能是apache配置。 in your setup has the 'ChrootDir' set: 在您的设置中设置了'ChrootDir':

http://httpd.apache.org/docs/2.2/mod/mpm_common.html#chrootdir http://httpd.apache.org/docs/2.2/mod/mpm_common.html#chrootdir

This uses the syscall chroot() and the view for '/' dir for that process starts from this setup dir, and hence everything should be relative to it. 这使用了系统调用chroot(),并且该进程的'/'dir视图从此安装目录开始,因此一切都应该相对于它。

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

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