Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set ENV PATH of php and ffmpeg to use it inside PHP scripts with CLI like shell_exec()

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.

like image 451
Thomas Melcer Avatar asked Jun 12 '26 11:06

Thomas Melcer


1 Answers

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');

Alternative solution:

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

like image 68
Alex Lau Avatar answered Jun 15 '26 00:06

Alex Lau



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!