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/binand/usr/bin. There are multiple solutions to this.You can run
$ whereis ffmpegand see what you get. Based on the results, change your$cmdvariable. Ifwhereisreturns nothing, then your system doesn’t know where it is. You can add it to your$PATHenvironment 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/binthen you should just try changing your$cmdto this: