如何为apache + wsgi网站设置LD_LIBRARY_PATH [英] How to set LD_LIBRARY_PATH for apache+wsgi website
问题描述
在独立的命令脚本中使用库时,我必须将库路径添加到LD_LIBRARY_PATH
所以这适用于独立脚本:
#export LD_LIBRARY_PATH = / usr / local / lib:/ usr / local / lib64
#python script.py
现在,当我尝试通过Apache + wsgi使用这个python库时,需要通过相同的路径到apache工人。如何实现?
您是否需要编译和安装Python模块扩展库?如果是,则在编译和安装该Python模块时,将 LD_RUN_PATH
环境变量设置为库所在的目录。这样,位置嵌入在Python模块扩展本身中,您在运行时不需要 LD_LIBRARY_PATH
。
使用环境变量的唯一其他方法是在Apache的启动脚本中设置 LD_LIBRARY_PATH
,以便在Apache启动时,根据需要进行设置。这意味着使系统启动脚本变得虚弱,所以不是理想的或总是实用的。
最终的方法可能是有效的,但并不是一个很好的想法,甚至不会工作,是使用:
LoadFile/usr/local/lib/libmylib.so
$ Apache配置中的c $ c>
这将在启动时强制将特定库连接到Apache,但根据库的使用方式,这可能无法正常工作。
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?
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.
这篇关于如何为apache + wsgi网站设置LD_LIBRARY_PATH的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!