Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

$PATH environment variable for apache2 on mac

I am trying to get apache/php to recognize the path to my git. I have been researching and looking in all corners of the web and cannot find how to do this. Basically, no matter what I try, when I run echo phpinfo(); the Apache Environment path does not change from /usr/bin:/bin:/usr/sbin:/sbin. And when I run system('echo $PATH'); in PHP, it reads the same.

System Information:

  • Mac OSX (Lion)
  • Apache 2 (running as _www)
  • PHP 5.3.6

Here is what I have tried editing so far:

  • /etc/profile
  • ~/.bash_profile
  • ~/.profile
  • /etc/path
  • /etc/path.d/{NEW_FILE}

Nothing I have tried so far has changed the $PATH variable. Any ideas?

SOLUTION

So here is the final solution. I edited the

/System/Library/LaunchDaemons/org.apache.httpd.plist 

and added

<key>EnvironmentVariables</key> <dict>     <key>PATH</key>     <string>/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/git/bin</string> </dict> 
like image 513
Chuck Burgess Avatar asked Jul 26 '11 17:07

Chuck Burgess


People also ask

Where is $path on Mac?

How do I find the PATH variable on a Mac? To find the PATH variable on Mac, open a terminal window and run echo $PATH. After which, the shell will return a list of all the directories currently listed under the PATH environment variable on your Mac.

What does $path do in Mac?

You can specify a set of directories where executable programs are located using $PATH. The $PATH variable is specified as a list of directory names separated by colon (:) characters.

How do I pass an environment variable in Apache?

The most basic way to set an environment variable in Apache is using the unconditional SetEnv directive. Variables may also be passed from the environment of the shell which started the server using the PassEnv directive.


2 Answers

You can set the PATH environment variable in /System/Library/LaunchDaemons/org.apache.httpd.plist.

More in the docs.

like image 106
Monolo Avatar answered Sep 21 '22 03:09

Monolo


Did you update the PATH environment variable of user '_www'? Apache will read environment variables from the user runs itself. Or, it looks like you didn't restart apache after updating PATH environment variable.

  • Check out the older discussion :
    • How do I add paths to the Apache PATH variable?
    • Setting environment variables in OS X?

And if you want to modify environment variable in PHP, getenv() and putenv() can be a better choice.

  • getenv : http://php.net/manual/en/function.getenv.php
  • putenv : http://www.php.net/manual/en/function.putenv.php

    $path = getenv('PATH'); putenv( "PATH=$path:/new_path_that_you_want_to_add" );

like image 35
lqez Avatar answered Sep 21 '22 03:09

lqez