mod_wsgi: previous DYLD_LIBRARY_PATH environment value (possibly all other variables as well) is empty when modified in generated apachectl script.

I am deploying a cx_Oracle dependant WSGI app so need to have my DYLD_LIBRARY_PATH set to the correct instantclient location (containing the needed dlls). I generate the apache server configuration files using mostly default settings mod_wsgi-express setup-server ....

When I set my environment variables and call the script, the DYLD_LIBRARY_PATH disappears and gets replaced with the ../site-packages/mod_wsgi_packages/httpd/lib: path. The intention of appending the previous value doesn’t work and I believe this is due to the shebang env line (6th paragraph in this answer)

# ./server script
set -x
export DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH
set +x
generated-apache-server-home/apachectl $@
# generated apachectl, I've placed set -x in there for debugging purposes
#!/usr/bin/env bash
...
SHLIBPATH="/path/to/venv/lib/python2.7/site-packages/mod_wsgi_packages/httpd/lib"

if [ "x$SHLIBPATH" != "x" ]; then
    set -x
    DYLD_LIBRARY_PATH="$SHLIBPATH:$DYLD_LIBRARY_PATH"
    set +x
    export DYLD_LIBRARY_PATH
fi

DYLD_LIBRARY_PATH is not set:

$ ./server start
++ export DYLD_LIBRARY_PATH=/path/to/instantclient_11_2
++ DYLD_LIBRARY_PATH=/path/to/instantclient_11_2
++ set +x
+ DYLD_LIBRARY_PATH=/path/to/venv/lib/python2.7/site-packages/mod_wsgi_packages/httpd/lib:
+ set +x

I am in a virtualenv and can echo $DYLD_LIBRARY_PATH the correct value.

UPDATE:

Also worth noting that using the mod_wsgi-express setup-server --setenv option has no effect:

# generated httpd.conf
...
SetEnv 'DYLD_LIBRARY_PATH' '/path/to/instantclient_11_2'
...
# a python file I know is in the server
import os
print("DYLD_LIBRARY_PATH={}".format("" if "DYLD_LIBRARY_PATH" not in os.environ else os.environ["DYLD_LIBRARY_PATH"]))
#output
[Fri Oct 07 09:59:25.304172 2016...] DYLD_LIBRARY_PATH=/path/to/venv/lib/python2.7/site-packages/mod_wsgi_packages/httpd/lib:

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 20 (11 by maintainers)

Most upvoted comments

It is only their for extreme cases where someone can’t install Apache httpd themselves or not part of operating system already. I didn’t even think I mentioned mod_wsgi-httpd on PyPi page for mod_wsgi or in any other instructions.

To clean up and start over you would need to uninstall both mod_wsgi and mod_wsgi-httpd packages. Then install just mod_wsgi.

pip uninstall mod_wsgi mod_wsgi-httpd
pip install mod_wsgi