Setting PATH for Apache on OSX
I use virtualenv to manage my Python development environment and use the latest MacPorts Python. Recently I had to work on some CGI Python scripts. Out of the box, Apache web server runs in the default OSX environment, so the CGI scripts run with the system Python and can’t use any of the Python packages installed using virtualenv. The Apache SetEnv directive allows you to set environment variables, such as PYTHONPATH, but changes to the PATH environment variable are ignored.
To change the PATH for Apache, with OSX Lion, edit /System/Library/LaunchDaemons/org.apache.httpd.plist and after the first <dict> tag add the following, where <string> contains the PATH that you want.
<key>EnvironmentVariables</key>
<dict>
<key>PATH</key>
<string>/opt/local/bin:/opt/local/sbin:/opt/local/Library/Frameworks/Python.framework/Versions/2.7/bin:/usr/bin:/bin:/usr/sbin:/sbin</string>
</dict>
Then restart Apache. This CGI-script will let you see the CGI enviroment variables (not for production environments!).
#!/usr/bin/env python
import os
print "Content-Type:text/plain" print ""
for param in os.environ.keys():
print "%20s %s" % (param,os.environ[param])




Trackbacks & Pingbacks
Comments are closed.