I'm trying to execute ffmpeg from PHP using shell_exec or exec but it fails. Why can this be? The command /usr/bin/ffmpeg
works from the terminal, so I tried
<?php
$cmd = "/usr/bin/ffmpeg";
exec($cmd." 2>&1", $out, $ret);
if ($ret){
echo "There was a problem!\n";
print_r($out);
}else{
echo "Everything went better than expected!\n";
}
?>
and I keep on getting
There was a problem! Array ( [0] => sh: /usr/bin/ffmpeg: not found )
Any help would be greatly appreciated.
Permission on the executable are
-rwxr-xr-x 1 root root 106552 Jun 12 09:53 ffmpeg
Running which /usr/local/bin/ffmpeg
into $cmd returns an empty Array.
The answer to your question might be simpler than expected. You're checking in both /usr/local/bin
and /usr/bin
. There are multiple solutions to this.
You can run $ whereis ffmpeg
and see what you get. Based on the results, change your $cmd
variable. If whereis
returns nothing, then your system doesn't know where it is. You can add it to your $PATH
environment variable and try again.
You can try to run $ find /usr -name "ffmpeg"
or something similar. By ensuring that this program is installed, it will help you resolve this quicker.
If there is some sort of restriction denying apache the ability to access/use ffmpeg, you can always store it in a bin folder within your document root. (something like /path/to/doc/root/bin/ffmpeg) I have done this before so I know it works.
If you find that ffmpeg is actually located in /usr/local/bin
then you should just try changing your $cmd
to this:
$cmd = '/usr/local/bin/ffmpeg';
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With