I’m having a weird problem. I have installed ffmpeg on my server. When I run “ffmpeg
” from SSH (PuTTY) it confirms the install:
Then I placed the following code in a PHP file, inside a website on the same server:
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
$output = exec('ffmpeg -h');
echo "<pre>$output</pre>";
?>
However when I run the PHP script, the page is blank, there is no output. I can confirm that exec
is working fine, because when I run php -v | grep cli
both in PHP and in terminal, they both output the same thing.
I am using Plesk (web host edition) to manage the site, and have given it access to the server over SSH (/bin/sh)
What am I missing here?
2
Answers
You want to use the full path to
ffmeg
as it’s likely not in the webserver user’s path environment variable.Also, the return of
exec()
is the last line of output, which may be a blank line, you never know. So use the second parameter to capture all output in an array:Or you can try
system()
orpassthru()
to output directly:I would recommend trying
EDIT – ADDITION
However, the issue in this case is that files in /root are not available to the web server user for security reasons. The ffmpeg executable should go into
/usr/local/bin
or another directory where it is available to the web server user.