1

I need a apache /php to recognize ffmpeg command without specifing the full bath of /usr/local/bin/ffmpeg

calling ffmpeg from command line executes the program calling ffmpeg from php via web does not execute the program calling /usr/local/bin/ffmpeg from php via web does execute the program

why: a php script calls youtube-dl (a compiled program) and executes ffmpeg internally

thank you in advance - tried ffmpeg path: which ffmpeg /usr/local/bin/ffmpeg

echo $PATH
/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin


#php code for testing:
$output = shell_exec('/usr/local/bin/ffmpeg 2>&1');
echo "shell exec /usr/local/bin/ffmpeg <pre>$output</pre>";
#Response:
ffmpeg version 2.5.3 Copyright #(good)

#Second php code for testing:
$output = shell_exec('ffmpeg 2>&1');
echo "shell exec <pre>$output</pre>";
#Response:
sh: ffmpeg: command not found #(bad)

1 Answers1

1

PHP uses default profile to execute commands with backticks/shell_exec. It apparently does not include /usr/local/bin in the $PATH. To fix the problem you might explicitly add /usr/local/bin to your default path:

sudo echo '$PATH=/usr/local/bin:$PATH' > /etc/profile.d/php_needed.sh

In modern systems the whole content of /etc/profile.d folder will be included in the profile.

Aleksei Matiushkin
  • 119,336
  • 10
  • 100
  • 160
  • thank you i ran that command, along with updatedb, hash -r restarted httpd and php/apache still says ffmpeg command not found –  Feb 14 '15 at 06:42
  • the contents of /etc/profile.d/php_needed.sh are $PATH=/usr/local/bin:$PATH –  Feb 14 '15 at 06:43
  • Well, it always worked for me, sorry for misleading you. Try these: http://stackoverflow.com/questions/3428647/php-exec-path-variable-missing-elements – Aleksei Matiushkin Feb 14 '15 at 06:48
  • 1
    thank you putenv("PATH=" .$_ENV["PATH"]. ':/usr/local/bin:/usr/bin:/bin'); how can i thank u more –  Feb 14 '15 at 06:52
  • sorry one more question - thank you - before this i srewed up my $path stuff trying different things - when i login to to ssh via putty with root i get Last login: Sat Feb 14 05:25:58 2015 from 10.10.10.101 -bash: /usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin=/usr/local/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin: No such file or directory that never showed up how do i get rid of it ? and restore the path back to default –  Feb 14 '15 at 20:51
  • Put `PATH=/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin` as the very last string in your `/etc/profile` file. This should help. – Aleksei Matiushkin Feb 14 '15 at 20:56