Setting environment variables in mod_wsgi for Django

apache-2.2djangomod-wsgioracle

I'm running Django on an RHEL instance under Apache/mod_wsgi, and I'm having issues setting some environment variables for the Python process. All of the components (Apache, Python, mod_wsgi, external libraries) are built from source, not installed from the repos.

The specific issue is support for Oracle support. I am able to connect to Oracle instances without a problem if I set the ORACLE_HOME and LD_LIBRARY_PATH on the command line when firing up Python myself, but I can't seem to get those variables passed through to the WSGI process.

The specific error message I get in the Apache logs is:

ImproperlyConfigured: Error loading cx_Oracle module: libclntsh.so.11.1: cannot open shared object file: No such file or 

directory

I have tried setting the variables in the VirtualHost (using SetEnv), Apache's envvars file, the apache user's .bashrc file, and the .wsgi file (using os.environ['ORACLE_HOME']='...'), all with no effect. In the first three cases, the variables don't seem to make to to Python at all–printing os.environ['ORACLE_HOME'] indicates that no value has been set.

I have also tried rebuilding mod_wsgi.so from source with the LD_RUN_PATH evn var set, per the advice here: http://groups.google.com/group/modwsgi/browse_thread/thread/91dfa97330dfca2/474f818304d741d4
However, that was also ineffective.

What am I missing? How can I get those env vars successfully passed through? Thanks in advance!

Best Answer

In Ubuntu, placing

export ORACLE_HOME=<your oracle home>
export LD_LIBRARY_PATH=<your library path>

in /etc/apache2/envvars seems to do the trick.

If nothing else helps, you can edit your Apache startup scripts and put above export lines just before Apache daemon startup (I recall I did something like this looong time ago on Debian).