这是一个很长的问题,详细说明了我从一开始所做的一切。希望能帮助到你。我正在开发一个 django 应用程序,需要将其部署到生产服务器上。生产服务器是由 IT 管理的虚拟服务器,我没有 root 访问权限。他们授予我管理 /swadm 和 /home/swadm 中模块安装的权限。所以我计划做以下安排:
/swadm/etc/httpd/conf
我在哪里维护 httpd.conf/swadm/etc/httpd/user-modules
我在哪里维护我的 apache 模块(mod_wsgi)/swadm/var/www/django/app
我在哪里维护我的 django 代码/swadm/usr/local/python/2.6
我将使用 django、south 等模块维护我的 python 2.6.7 安装。/home/swadm/setup
我将在其中存储所需的源代码压缩包并进行所有构建和安装。/home/swadm/workspace
我将在其中维护正在开发的应用程序代码。
系统安装了 python2.4.3 和 python2.6.5,但如果我需要安装大量自定义模块(我会这样做),IT 建议我维护自己的 python 安装。
于是我下载了python2.6.7源码。我需要确保安装了 python,以便它的共享库可用。--enable-shared
当我只使用选项and运行配置脚本时--prefix=/swadm/usr/local/python/2.6
,它会被安装,但令人惊讶的是指向系统安装的 python2.6.5。
$ /swadm/usr/local/python/2.6/bin/python
Python 2.6.5 (r265:79063, Feb 28 2011, 21:55:45)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-50)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>
因此,我按照Building Python with --enable-shared in non-standard location中的说明运行了配置脚本
./configure --enable-shared --prefix=/swadm/usr/local/python/2.6 LDFLAGS="-Wl,-rpath /swadm/usr/local/python/2.6/lib"
还要确保我事先创建了目录(如链接所示)以避免预期的错误。现在键入/swadm/usr/local/python/2.6/bin/python
将启动正确的 python 版本 2.6.7。所以我继续配置和安装 mod_wsgi。我将其配置为
./configure --with-python=/swadm/usr/local/python/2.6/bin/python
创建的 Makefile 尝试将模块安装到/usr/lib64/httpd/modules
其中,我在那里没有写权限,所以我修改了 makefile 以安装到/swadm/etc/httpd/user-modules
. (可能有一个命令参数,但我无法弄清楚)。该模块创建得很好。我使用的测试 wsgi 脚本是
import sys
def application(environ, start_response):
status = '200 OK'
output = 'Hello World!'
output = output + str(sys.version_info)
output = output + '\nsys.prefix = %s' % repr(sys.prefix)
output = output + '\nsys.path = %s' % repr(sys.path)
response_headers = [('Content-type', 'text/plain'),
('Content-Length', str(len(output)))]
start_response(status, response_headers)
return [output]
显示的输出令人惊讶的是
Hello World!(2, 6, 5, 'final', 0)
sys.prefix = '/swadm/usr/local/python/2.6'
sys.path = ['/swadm/usr/local/python/2.6/lib64/python26.zip', '/swadm/usr/local/python/2.6/lib64/python2.6/', '/swadm/usr/local/python/2.6/lib64/python2.6/plat-linux2', '/swadm/usr/local/python/2.6/lib64/python2.6/lib-tk', '/swadm/usr/local/python/2.6/lib64/python2.6/lib-old', '/swadm/usr/local/python/2.6/lib64/python2.6/lib-dynload']`
所以你看到 mod_wsgi 模块仍然配置了系统的 python 2.6.5 安装,而不是我的自定义安装。我尝试了mod_wsgi 文档中详述的各种事情
WSGIPythonHome
在 httpd.conf 中设置to/swadm/usr/local/python/2.6
和WSGIPythonPath
to/swadm/usr/local/python/2.6/lib/python2.6
在 python config 目录中创建了一个符号链接以指向 libpython2.6.so 文件
$ ln -s ../../libpython2.6.so
当我这样做时ldd libpython2.6.so
,我看到的是:
$ ldd libpython2.6.so
linux-vdso.so.1 => (0x00007fffc47fc000)
libpthread.so.0 => /lib64/libpthread.so.0 (0x00002b666ed62000)
libdl.so.2 => /lib64/libdl.so.2 (0x00002b666ef7e000)
libutil.so.1 => /lib64/libutil.so.1 (0x00002b666f182000)
libm.so.6 => /lib64/libm.so.6 (0x00002b666f385000)
libc.so.6 => /lib64/libc.so.6 (0x00002b666f609000)
/lib64/ld-linux-x86-64.so.2 (0x00000031aba00000)
并ldd mod_wsgi.so
给出
$ ldd /swadm/etc/httpd/user-modules/mod_wsgi.so
linux-vdso.so.1 => (0x00007fff1ad6e000)
libpython2.6.so.1.0 => /usr/lib64/libpython2.6.so.1.0 (0x00002af03aec7000)
libpthread.so.0 => /lib64/libpthread.so.0 (0x00002af03b270000)
libdl.so.2 => /lib64/libdl.so.2 (0x00002af03b48c000)
libutil.so.1 => /lib64/libutil.so.1 (0x00002af03b690000)
libm.so.6 => /lib64/libm.so.6 (0x00002af03b893000)
libc.so.6 => /lib64/libc.so.6 (0x00002af03bb17000)
/lib64/ld-linux-x86-64.so.2 (0x00000031aba00000)
我一直在尝试重新安装和重新配置 python 和 mod_wsgi 但无济于事。请让我知道我哪里出错了。(对不起,很长的帖子)
TLDR ; 具有非 root 访问权限的系统具有默认的 python 安装。我正在维护自己的 python 和 python 模块。mod_wsgi 使用自定义 python 配置和构建,当我运行打印出 sys version_info 和路径的测试脚本时,它仍然指向系统的 python。
更新:在浏览stackoverflow(应该早点完成)时,我在mod_wsgi python2.5 ubuntu 11.04问题上找到了Graham Dumpleton的这个答案,它为我解决了错误。现在,当我这样做时,ldd mod_wsgi.so
我看到它链接到了正确的 python 共享库。我现在使用我的自定义 python 安装安装了 Django 和 MySQLdb。现在我面临这个错误:
The following error occurred while trying to extract file(s) to the Python egg
cache:
[Errno 13] Permission denied: '/var/www/.python-eggs'
The Python egg cache directory is currently set to:
/var/www/.python-eggs
Perhaps your account does not have write access to this directory? You can
change the cache directory by setting the PYTHON_EGG_CACHE environment
variable to point to an accessible directory.
所以我确实改变了PYTHON_EGG_CACHE
by doing的价值export PYTHON_EGG_CACHE=/swadm/var/www/.python-eggs
。但我仍然遇到同样的错误。我正在调查更多。当我解决这个问题时会更新。