1

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"
Antop
  • 123
  • 1
  • 1
  • 9
  • *"I have tried giving the exact route (/usr/bin/ffmpeg) but doesn't work."* What happens exactly? What are the errors? – llogan Nov 12 '19 at 18:49
  • I'm using PHP-FFMPeg (https://github.com/PHP-FFMpeg/PHP-FFMpeg) and returns me this error: "FFMpeg\Exception\ExecutableNotFoundException: Unable to load FFMpeg" – Antop Nov 12 '19 at 19:15

2 Answers2

0

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.

micha137
  • 1,195
  • 8
  • 22
-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 ');
Vishnu Raj
  • 136
  • 9
  • Thanks. What I didn't say is that I'm not using ffmpeg extension. I'm using PHP-FFMPeg (https://github.com/PHP-FFMpeg/PHP-FFMpeg), as you said. And it returns me the error "FFMpeg\Exception\ExecutableNotFoundException: Unable to load FFMPeg". Also extension_loaded(ffmpeg) returns me "false" – Antop Nov 12 '19 at 19:19
  • Permissions are OK also: everybody can execute ffmpeg – Antop Nov 12 '19 at 19:27
  • A very strange thing I've noticed is that I can't access any command via php: I tried using it with echo (Please see my edited post before) – Antop Nov 12 '19 at 19:32