我有一个我编写的C程序,名为convert3to5
,最初是在2010年初为CentOS/Fedora 32bit系统编写的。我将它移动到新的CentOS 6.x 64位系统主机。CentOS Linux控制台命令与PHP exec(命令)
从CentOS Putty控制台我可以运行convert3to5
命令就好了;这里是我的控制台运行它的一个样本:
[[email protected] convert3to5]# ls
CircleStar convert3to5 Convert3To5.txt test.tif
[[email protected] convert3to5]# ./convert3to5 /var/www/webadmin/data/www/mydomain.com/uploads/SV-DIS160217B.tif
TIFFReadDirectory: Warning, /var/www/webadmin/data/www/mydomain.com/uploads/SV-DIS160217B.tif: wrong data type 7 for "RichTIFFIPTC"; tag ignored. Image has an undefined fillorder - using default: MSB2LSB
以上是convert3to5的正常完成,我得到的是被放置在/var/www/webadmin/data/www/mydomain.com/uploads/
所以一个SV-DIS160217B.bmp
从控制台运行它工作正常。
的问题 - 我试图使用exec(command, output, return)
命令,如下所示从PHP运行完全相同的命令:
chdir($sv_path.$c3to5_path); //change our working directory to "/convert3to5" directory
$command = "./convert3to5 $targetFile 2>&1";
$result = exec($command, $output, $return);
// the output of the above command - is a .bmp file it will be placed in the same path as the input .tif file
我得到以下$结果:
ERROR: Unable to convert /var/www/webadmin/data/www/mydomain.com/uploads/SV-DIS160217B.tif to 5 color BMP file: Open file Error: Tiff_3_to_BMP_5_.lut!
我convert3to5确实需要打开Tiff_3_to_BMP_5_.lut
为什么当我从控制台p运行convert3to5
时发现Tiff_3_to_BMP_5_.lut
rompt但不能在这两种情况下我的PWD显示,我在
[[email protected] convert3to5]# pwd
/var/www/webadmin/data/www/mydomain.com/myView/convert3to5
PHP的exec(...)我也验证了PWD
chdir($sv_path.$c3to5_path);
Tiff_3_to_BMP_5_后是正确的,从我的PHP脚本。 lut是在CircleStar目录中 - CircleStar的路径是/var/www/webadmin/data/www/mydomain.com/myView/convert3to5/CircleStar
摘要:./convert3to5可以工作,而PHP exec('convert3to5 ..)似乎不起作用。
任何人都可以提出差异以及如何解决和/或调试? 谢谢
感谢您的信息;我解决了这个问题。从控制台我运行登录作为根(如此完整的特权)。从我的PHP后端脚本我想它运行为“apache”用户?我相信这是我遇到的问题:我查看了Tiff_3_to_BMP_5_.lut文件存在的CircleStar目录权限。 CircleStar在从控制台以root身份运行时具有rw-r-r--(0644),这允许我的convert3to5程序找到Tiff_3_to_BMP_5_.lut文件就好了。然而,不是PHP exec(...)一旦我将CircleStar上的特权更改为rwxr-xr-x PHP exec(...)运行良好! –
很高兴你知道了! – wonton