开发者

$PATH environment variable for apache2 on mac

I am trying to get ap开发者_StackOverflow社区ache/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>


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

More in the docs.


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


Important note for El Capitan (Apologies for the new answer - I don't have enough Rep to comment)

On OSX 10.11, the /System/Library folder is protected, so the files can't be edited.

You need to:

  • Reboot into Recovery Mode (hold CMD + r after the startup sound)
  • Once in recovery mode, go to Utilities > Terminal
  • Run: csrutil disable
  • Reboot back into OSX - you should now be able to change the files
  • Once done, go back to recovery mode and run csrutil enable

Hope that helps


I created this gist that helped me out from the information above:

https://gist.github.com/srayhunter/5208619

My problem was that PHP was not finding a program that we had installed under /usr/local/bin. Once we did the above it all worked and played nice on mac osx.


for ubuntu server, in /etc/apache2/envvars, for centos server, in /etc/sysconfig/httpd, to add:

export PATH=<your php cli path>

and restart apache


A similar problem to what I was having installing Derby. The way I solved it was by opening TextEdit. Select File > Open at this point press Shift + Command + . , this will allow you to view all the documents. Head to the user directory and search for a file called ".profile" . Open it and add the export VARIABLE= Value line for example:

export DERBY_HOME=/opt/local/share/java/derby/

Save the document and restart your terminal to see if the changes went into affect.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜