skip to Main Content

I’m having a weird problem. I have installed ffmpeg on my server. When I run “ffmpeg” from SSH (PuTTY) it confirms the install:

ffmpeg via ssh

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


  1. 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:

    exec('/path/to/ffmpeg -h', $output);
    echo implode('<br>', $output);
    

    Or you can try system() or passthru() to output directly:

    echo "<pre>" . system('/path/to/ffmpeg -h') . "</pre>";
    
    Login or Signup to reply.
  2. I would recommend trying

    $command = escapeshellcmd('/root/bin/ffmpeg -h');
    $output = shell_exec($command);
    echo "<pre>$output</pre>";
    

    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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search