我不熟悉使用基于django的应用程序,并且尝试使用以下配置部署django项目,这些配置几乎与django文档中给出的默认配置相似。
apache2.conf文件
# WSGI Configuration
WSGIDaemonProcess demo python-path=/home/inian/Documents/demo
WSGIProcessGroup demo
WSGIScriptAlias / /home/inian/Documents/demo/demo/wsgi.py process-group=demo
<Directory /home/inian/Documents/demo/demo>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
# Serving static files
Alias /static/ /home/inian/Documents/demo/static/
<Directory /home/inian/Documents/demo/static>
Require all granted
</Directory>
当我启动apache服务器时,它会正常启动,但由于python版本不匹配,在加载项目时会出现运行时错误,如下所示。
/var/log/apache2/error.log/错误日志
[Sun Apr 10 20:38:16.165536 2016] [wsgi:warn] [pid 22959] mod_wsgi: Compiled for Python/2.7.11.
[Sun Apr 10 20:38:16.165551 2016] [wsgi:warn] [pid 22959] mod_wsgi: Runtime using Python/2.7.10.
[Sun Apr 10 20:38:16.166787 2016] [mpm_prefork:notice] [pid 22959] AH00163: Apache/2.4.7 (Ubuntu) OpenSSL/1.0.1f mod_wsgi/4.5.1 Python/2.7.10 configured -- resuming normal operations
我希望我的应用程序使用安装在
/usr/local
位置的python,这是2.7.11
版本,这是我用来编译和安装mod_wsgi
的python,但是为了安全起见,我还选中了/usr/bin/python -V
,它将输出设置为Python 2.7.6
。这带来了两个问题:如何让apache从安装位置使用Python 2.7.11(我一直将其用作服务器上所有东西的默认设置)。
我不记得在2.7.10上安装或做过什么,所以我不知道apache是如何从何处加载和使用它的如果有人能引导我走向那一步,那也会很棒。
最佳答案
如果mod_wsgi是针对特定的python安装编译的,然后python安装被升级,则这是一条警告消息。因为共享库是如何工作的,所以这通常不重要。记录在:
http://modwsgi.readthedocs.org/en/develop/user-guides/installation-issues.html#python-patch-level-mismatch
在您的例子中,尽管问题是您的mod_wsgi不是针对python的安装进行编译的,但它在运行时找到了python共享库。这可能会导致各种问题,其中之一是两个python安装没有安装兼容的编译器标志集,例如unicode字符宽度的标志集。
因此,在我看来,基本上这个问题看起来像是您根据/usr/local中的python安装从源代码编译了mod_wsgi,但是由于它的构建方式不适合该场景,所以在运行时,它会为安装到/usr中的版本找到python共享库。
有关如何在Linux系统上正确安装Python的重要讨论,请阅读:
http://blog.dscpl.com.au/2015/06/installing-custom-python-version-into.html
接下来,当您从源代码处编译mod_wsgi时,请确保将LD_RUN_PATH
环境变量设置为包含安装备用Python安装的Python共享库所在的库目录该环境变量将允许mod_wsgi在运行时找到正确的库,而不使用/usr/lib中的版本。
您可以通过以下文档中的说明来验证它是否找到了错误/正确的:
http://modwsgi.readthedocs.org/en/develop/user-guides/checking-your-installation.html#python-shared-library
最后,一旦安装了mod_wsgi并找到正确的共享库,您可能还必须在Apache配置中设置WSGIPythonHome
指令,以便它为运行时文件找到正确的Python安装文档中对此进行了描述,网址为:
http://modwsgi.readthedocs.org/en/develop/user-guides/installation-issues.html#multiple-python-versions