简体   繁体   English

Django部署:配置apache / mod_wsgi使用的正确python

[英]Django deployment: configuring correct python to be used by apache/mod_wsgi

I am new to working with Django based applications and trying to deploy a django project using following configurations, which are almost similar to the default given on django docs. 我是新手使用基于Django的应用程序并尝试使用以下配置部署django项目,这几乎与django docs上给出的默认设置类似。

apache2.conf 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>

When I start the apache server, it starts normally but gives runtime error for loading my project because of python version mismatch indicated as bellow. 当我启动apache服务器时,它正常启动但由于python版本不匹配,因此加载我的项目时出现运行时错误。

/var/log/apache2/error.log /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

I want my application to use the python installed in location /usr/local which is version 2.7.11 and this is the one I used to compile and install mod_wsgi , however just to be safe I also checked /usr/bin/python -V which gives output as Python 2.7.6 . 我希望我的应用程序使用安装在位置/usr/local的版本为2.7.11 ,这是我用来编译和安装mod_wsgi那个,但为了安全我还检查了/usr/bin/python -V它提供输出为Python 2.7.6 This brings use to two issues: 这可以用于两个问题:

  1. How can I point apache to use Python 2.7.11 from the installation location /usr/local/bin/python (which I have been using as default for all things on the server). 我怎样才能指出apache从安装位置/usr/local/bin/python使用Python 2.7.11(我一直使用它作为服务器上所有东西的默认设置)。

  2. I do not remember ever installing or doing anything with 2.7.10, so I do not know how and from where is it being loaded and used by apache. 我不记得曾经安装或使用2.7.10进行任何操作,因此我不知道apache如何以及从何处加载和使用它。 If someone can guide me towards that, then it will be great as well. 如果有人可以指导我,那么它也会很棒。

It is a warning message in the case where mod_wsgi was compiled against a specific Python installation and then the Python installation was upgraded. 在针对特定Python安装编译mod_wsgi然后升级Python安装的情况下,这是一条警告消息。 Because of how shared libraries work, it shouldn't normally matter. 由于共享库的工作方式,它通常不重要。 This is documented in: 这记录在:

In your case though the problem is that your mod_wsgi is not compiled against the installation of Python it is finding the Python shared library for at runtime. 在你的情况下,虽然问题是你的mod_wsgi没有针对Python的安装进行编译,但它是在运行时找到Python共享库。 This can cause various problems, one being where the two Python installations were not installed with compatible sets of compiler flags, such as those for width of Unicode characters. 这可能会导致各种问题,其中一个问题是两个Python安装没有安装兼容的编译器标志集,例如Unicode字符宽度的问题。

So basically the problem looks to me like you compiled mod_wsgi from source code against a Python installation in /usr/local, but because how it was built wasn't correct for that scenario, at run time it is finding the Python shared library for the version installed into /usr. 基本上这个问题在我看来就像你从/ usr / local中的Python安装源代码编译mod_wsgi,但是因为它的构建方式不正确,在运行时它会找到Python的共享库版本安装到/ usr。

For a big discussion of how Python should be installed properly on Linux systems go read: 有关如何在Linux系统上正确安装Python的大讨论,请阅读:

Next, when you are compiling mod_wsgi from source, ensure you set the LD_RUN_PATH environment variable to include the library directory where the Python shared library for your alternate Python installation is installed. 接下来,当您从源代码编译mod_wsgi时,请确保将LD_RUN_PATH环境变量设置为包含用于安装备用Python安装的Python共享库的库目录。 That environment variable will allow mod_wsgi to find the correct library at run time and not use the version in /usr/lib. 该环境变量将允许mod_wsgi在运行时找到正确的库,而不使用/ usr / lib中的版本。

You can verify it is finding the wrong/right one by following instructions in documentation at: 您可以按照以下文档中的说明验证是否找到了错误的/正确的:

Finally, once you have mod_wsgi installed and finding the correct shared library, you may also have to set WSGIPythonHome directive in Apache configuration so that it finds the correct Python installation for run time files. 最后,一旦安装了mod_wsgi并找到了正确的共享库,您可能还必须在Apache配置中设置WSGIPythonHome指令,以便为运行时文件找到正确的Python安装。 This is described in the documentation at: 这在以下文档中描述:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM