Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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
share|improve this question
    
What are the permissions on ffmpeg? Have you tried specifying the absolute path to ffmopeg instead of relying on detection at runtime? does your webserver run chroot? –  symcbean Oct 20 '10 at 14:05
    
....and what happens when you try to run it using 'su apache -c ffmpeg -i ....' –  symcbean Oct 20 '10 at 14:06
    
Apparently I can't su into apache... I do have apache as a user though –  siliconpi Oct 21 '10 at 8:16
    
Symcbean - are you able to su apache? –  siliconpi Oct 21 '10 at 9:14
    
When you say "None worked", did you pass it actual arguments so as to see if it would convert? –  Ignacio Vazquez-Abrams Oct 25 '10 at 7:57

2 Answers 2

A few random thoughts:

  • How long does your ffpmpeg command takes ? if it takes longer than the value of max_execution_time in php.ini, I believe that the command is canceled.

  • try to use only full paths for the ffmpeg binary and the input/output files. Although, if you have a zero size file outputted, it shouldn't be that.

  • Does apache have the permission to run the ffmpeg binary ?

  • try a basic command in your system call, such as "touch test.txt" just to check if the problem is from ffmpeg or your php script.

share|improve this answer
    
I dont think (1) is a problem. I've set the max_exec time to 5 mins. (2) ffmpeg is in the system path (3) I'm not sure! How do I test that? (4) you're right - this did NOT work - no file was created. –  siliconpi Oct 21 '10 at 9:25
    
(1)is 5 minutes enough to encode your video ?. (3) what does "ps -edf|grep apache" returns ? the first column is the name of the user that runs apache, try to use it with "su <user> -c ffmpeg...". (4) this is a coding problem. can't help here. –  Julien Vehent Oct 21 '10 at 10:09
    
ps -edf... returns: apache 19394 9134 0 10:07 ? 00:00:00 /usr/sbin/httpd apache 19395 9134 0 10:07 ? 00:00:00 /usr/sbin/httpd apache 19396 9134 0 10:07 ? 00:00:00 /usr/sbin/httpd apache 19397 9134 0 10:07 ? 00:00:00 /usr/sbin/httpd apache 19398 9134 0 10:07 ? 00:00:00 /usr/sbin/httpd apache 19399 9134 0 10:07 ? 00:00:00 /usr/sbin/httpd apache 19400 9134 0 10:07 ? 00:00:00 /usr/sbin/httpd apache 19401 9134 0 10:07 ? 00:00:00 /usr/sbin/httpd root 19960 16055 0 10:28 pts/1 00:00:00 grep apache –  siliconpi Oct 21 '10 at 10:29
    
I can't su apache... it says: This account is currently not available. –  siliconpi Oct 21 '10 at 10:29
    
<?php echo system("ls -al"); ?> doesnt work either –  siliconpi Oct 21 '10 at 10:41

It was a permissions issue, I had selinux enabled. By changing the setting in /etc/sysconfig/selinux

From: 
SELINUX=enforcing

To:
SELINUX=disabled

The system() commands started working

share|improve this answer
    
Whoops! Spoke too soon... see edit2 –  siliconpi Oct 22 '10 at 10:31

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.