在写入文件夹的php脚本中运行system()命令需要什么权限?

我有一个PHP脚本的行:

system("ffmpeg -i ......"); 

输出文件夹设置为:

 drwxrwxr-x 5 apache apache 4096 Oct 19 07:40 in_upload 

如果我以root身份从提示运行确切的文本“ffmpeg -i ……”,它工作正常。

但是如果脚本运行,只会创build一个零大小的文件。 任何想法可能是错的?


编辑1

我想我已经将问题本地化到了selinux

我尝试了http://www.php.net/manual/en/function.system.php#94929中推荐的解决scheme:

 <?php function my_exec($cmd, $input='') {$proc=proc_open($cmd, array(0=>array('pipe', 'r'), 1=>array('pipe', 'w'), 2=>a$ fwrite($pipes[0], $input);fclose($pipes[0]); $stdout=stream_get_contents($pipes[1]);fclose($pipes[1]); $stderr=stream_get_contents($pipes[2]);fclose($pipes[2]); $rtn=proc_close($proc); return array('stdout'=>$stdout, 'stderr'=>$stderr, 'return'=>$rtn ); } echo "1 "; echo shell_exec('ls'); echo "\n2 "; my_exec('ls'); echo "\n3 "; my_exec('/bin/ls'); ?> 

输出是:

 1 2 3 

编辑2

禁用selinux后,我得到了以下结果:

 echo "1 "; echo shell_exec('ffmpeg'); echo "\n2 "; echo system('ffmpeg'); echo "\n3 "; echo exec('ffmpeg'); ===> None worked echo "1 "; echo shell_exec('/usr/bin/ffmpeg'); echo "\n2 "; echo system('/usr/bin/ffmpeg'); echo "\n3 "; echo exec('/usr/bin/ffmpeg'); ===> None worked echo "1 "; echo shell_exec('ls'); echo "\n2 "; echo system('ls'); echo "\n3 "; echo exec('ls'); ===> All 3 worked as expected. 

编辑3

PHP脚本:

 echo "1 "; echo shell_exec('touch test1.txt'); echo "\n2 "; echo system('touch test2.txt'); echo "\n3 "; echo exec('touch test3.txt'); 

error_log中:

 touch: cannot touch `test1.txt': Permission denied touch: cannot touch `test2.txt': Permission denied touch: cannot touch `test3.txt': Permission denied 

PHP脚本:

 echo "1 "; echo shell_exec('/bin/touch test1.txt'); echo "\n2 "; echo system('/bin/touch test2.txt'); echo "\n3 "; echo exec('/bin/touch test3.txt'); 

error_log中:

 /bin/touch: cannot touch `test1.txt': Permission denied /bin/touch: cannot touch `test2.txt': Permission denied /bin/touch: cannot touch `test3.txt': Permission denied 

PHP脚本:

 echo "1 "; echo shell_exec('/bin/touch /var/www/html/beta/test1.txt'); echo "\n2 "; echo system('/bin/touch /var/www/html/beta/test2.txt'); echo "\n3 "; echo exec('/bin/touch /var/www/html/beta/test3.txt'); 

error_log中:

 /bin/touch: cannot touch `/var/www/html/beta/test1.txt': Permission denied /bin/touch: cannot touch `/var/www/html/beta/test2.txt': Permission denied /bin/touch: cannot touch `/var/www/html/beta/test3.txt': Permission denied 

一些随意的想法:

  • 你的ffpmpeg命令需要多长时间? 如果它在php.ini中的时间超过了max_execution_time的值,我相信这个命令被取消了。

  • 尝试只使用ffmpeg二进制文件和input/输出文件的完整path。 虽然,如果你有一个零大小的文件输出,它不应该是这样的。

  • apache是​​否有权限运行ffmpeg二进制文件?

  • 在你的系统调用中尝试一个基本的命令,比如“touch test.txt”,以检查问题是来自ffmpeg还是你的php脚本。

这是一个权限问题,我启用了selinux。 通过更改/ etc / sysconfig / selinux中的设置

 From: SELINUX=enforcing To: SELINUX=disabled 

system()命令开始工作