I would like to execute commands in a php script like this:
<?php
shell_exec(php myfile.php)
or
<?php
shell_exec(ffmpeg -i ...)
My problem, i think is that php and ffmpeg path are not properly configured in my apache environment because when i execute this:
<?php
var_dump(shell_exec("which php"));
var_dump(shell_exec("which ffmpeg"));
I get this answer:
string '/usr/bin/php' (length=13)
null
But in the terminal when i type:
which php
which ffmpeg
I get this answer:
/usr/local/opt/php55/bin/php
/usr/local/bin/ffmpeg
So how can i set properly the php and ffmpeg environment path without always retype the complete path ?
I am under Mac OsX 10.10 and i installed php and ffmpeg whith brew.
You may put environment variables in the command just like in shell.
Examples:
shell_exec('PATH=/usr/local/bin:/usr/local/opt/php55/bin:$PATH which ffmpeg');
In case you do not want to make the code dirty, you may configure your Apache environment variables as follow.
Mac:
Edit
/System/Library/LaunchDaemons/org.apache.httpd.plist
and added
<key>EnvironmentVariables</key>
<dict>
<key>PATH</key>
<string>/usr/local/bin:/usr/local/opt/php55/bin:/usr/bin:/bin:/usr/sbin:/sbin</string>
</dict>
(answer copied from $PATH environment variable for apache2 on mac)
Other platforms: (for your references)
https://serverfault.com/questions/151328/setting-apache2-path-environment-variable
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With