3

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.

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks you solved my problem ;) now when i do var_dump(shell_exec("which php")); i get the right path. But the var_dump(getenv('PATH')); give me again string '/usr/bin:/bin:/usr/sbin:/sbin' (length=29). Is it normal ?
0

Add ffmpeg to your PATH environment variable, restart Apache server and retry

7 Comments

I already added ffmpeg and php in my environment variable in my .bash_profile like this : export PATH="$(brew --prefix homebrew/php/php55)/bin:/usr/local/mysql/bin:/usr/local/sbin:$PATH". So this is why i have access in my terminal to the right path when i type which php or which ffmpeg but this not spread to my apache server
have you restarted your apache after that ?
Yes i did but nothing change
please, var_dump(getenv('PATH'));
string '/usr/bin:/bin:/usr/sbin:/sbin' (length=29)
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.