I've got a php script which has the line:
system("ffmpeg -i ......");
The output folder is set to be:
drwxrwxr-x 5 apache apache 4096 Oct 19 07:40 in_upload
If I run the exact text "ffmpeg -i ......" from the prompt as root, it works fine.
But if the script is run, only a zero sized file is created. Any ideas on what could be wrong?
Edit 1
I think I've localized the problem to selinux
I tried the solution recommended in http://www.php.net/manual/en/function.system.php#94929 :
<?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');
?>
Output was:
1
2
3
Edit 2
AFTER disabling selinux, I got the following results:
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.
Edit 3
php script:
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 script:
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 script:
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