Reputation: 2497
I've recently installed Apache 2.4 on my Mac via Homebrew. (I previously used the Apple-supplied Apache.)
In a PHP script, I call Exec(x) on a executable located in /usr/local/bin, but it fails because /usr/local/bin is not included in Apache's PATH environment variable. Running phpinfo() shows that PATH is /usr/bin:/bin:/usr/sbin:/sbin.
I had previously included /usr/local/bin in /System/Library/LaunchDaemons/org.apache.httpd.plist as described here, but it no longer works, I think because I'm using Apache installed by Homebrew.
My shell $PATH includes many directories including /usr/local/bin, so that's not it.
I'd rather not call Exec with an absolute path since I need to run this in several environments where the executable is in different paths.
How do I modify the Homebrew Apache's PATH variable? Thanks!
Upvotes: 1
Views: 1659
Reputation: 2497
I found the answer here.
To change Apache environment variables when Apache was installed with Homebrew, edit the homebrew.mxcl.httpd24.plist file located in /usr/local/Cellar/httpd24/your version of Apache/.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>homebrew.mxcl.httpd24</string>
<!-- add this -->
<key>EnvironmentVariables</key>
<dict>
<key>PATH</key>
<string>/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin</string>
</dict>
<!-- end add -->
<key>ProgramArguments</key>
<array>
<string>/usr/local/opt/httpd24/bin/httpd</string>
<string>-D</string>
<string>FOREGROUND</string>
</array>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>
Then restart Apache.
Upvotes: 2