How to set LD_LIBRARY_PATH for apache+wsgi website

2019-07-15 04:06发布

问题:

I'm trying to use a python library in my wsgi( apache + flask) based website.

While using the library in a standalone command script, I have to add the library path to LD_LIBRARY_PATH

So this works for standalone script:

# export LD_LIBRARY_PATH=/usr/local/lib:/usr/local/lib64
# python script.py

Now when I try to use this python library through Apache+wsgi, I need to pass the same path to apache workers. How can I accomplish that?

回答1:

Is the library required by a Python module extension you have compiled and installed? If it was, set LD_RUN_PATH environment variable to the directory the library is in when compiling and installing that Python module. That way the location is embedded in the Python module extension itself and you don't need LD_LIBRARY_PATH at run time.

The only other way to do it using environment variables is to set LD_LIBRARY_PATH in the startup scripts for Apache so that when Apache is started it is set as you require. This means fiddling with system startup scripts so is not ideal or always practical.

One final way which may work but isn't really that great of an idea and may not even work, is to use:

LoadFile "/usr/local/lib/libmylib.so"

in the Apache configuration. This will force linking of the specific library into Apache at startup, but depending on how the library is being used, this may not work.