skip to Main Content

I have installed FFMPeg in CentOS. It works perfectly.
It’s inside /usr/bin directory. Also, I have PHP 7.2.24 that comes with Plesk 18.0.20.

I want to use FFMPeg inside a PHP script, but that script can’t find the executable of FFMpeg. I have tried giving the exact route (/usr/bin/ffmpeg) but doesn’t work.

It’s a production server. The same script, in my development server (macOS) works perfectly.

I tried using:

var_dump(getenv('PATH'));
var_dump(exec('which ffmpeg'));
var_dump(ini_get('open_basedir'));
var_dump(is_file(exec('which ffmpeg')));
var_dump(is_executable(exec('which ffmpeg')));

And it returns me:

string(49) "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin"
string(0) ""
string(44) "/var/www/vhosts/name-of-the-domain.com/:/tmp/"
bool(false)
bool(false)
NULL

¿What could be happening?

A very strange thing I’ve noticed is that I can’t access any command via php:
I tried using it with echo

var_dump(exec('which echo'));
var_dump(is_file(exec('which echo')));
var_dump(is_executable(exec('which echo')));

And it returns me:

string(0) ""
bool(false)
bool(false)
NULL

And the permissions are right:

[root@vps bin]# ls -lha echo
-rwxr-xr-x 1 root root 33K ago 20 08:25 echo

[root@vps bin]# ls -lha ffmpeg
-rwxr-xr-x 1 root root 217K abr  4  2019 ffmpeg

But if I make a

var_dump(exec('echo "HELLO"'))

it returns me

string(5) "HELLO"

2

Answers


  1. I think to use FFMPFG with php, the fastest way is to use PHP-FFMPEG package. https://github.com/PHP-FFMpeg/PHP-FFMpeg
    The issue seems to be related to permissions to execute I think.

    Can you try to test it to check if the FFMPEG was loaded? Maybe PHP extension might not be loaded on your server.

    Try adding this code to test if ffmpeg is loaded

    <?php if (! extension_loaded (ffmpeg)) exit ('ffmpeg was not loaded ');
    
    Login or Signup to reply.
  2. Check whether the PHP Extension Suhosin (using phpinfo) or Security enhanced Linux (using sestatus) are installed on your server.

    Suhosin has a feature to blacklist functions and SELinux might forbid execution because of mismatching file contexts.

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