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.

Thomas Melcer
  • 163
  • 2
  • 13

2 Answers2

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

Community
  • 1
  • 1
Alex Lau
  • 1,687
  • 10
  • 17
  • 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 ? – Thomas Melcer Feb 24 '15 at 12:09
0

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

Halayem Anis
  • 7,654
  • 2
  • 25
  • 45