user4558052
user4558052

Reputation:

call ffmepg from apache php without full path

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)

Upvotes: 1

Views: 905

Answers (1)

Aleksei Matiushkin
Aleksei Matiushkin

Reputation: 121000

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.

Upvotes: 1

Related Questions