Jun 7, 2012
tom

Setting environment variables in mod_wsgi for Django

Question

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!

Answer

The key seems to have been adding the Oracle libraries to ld.so.conf.

Related posts:

  1. Django setting environment variable globally
  2. mod_wsgi+Django with a different Python version
  3. How to set system environment variables for Linux services?
  4. Windows + Django + mod_wsgi = “DLL load failed”
  5. Run Mod_Python with Mod_WSGI on Apache for Django — Segmentation fault (11)

Leave a comment