bawejakunal
bawejakunal

Reputation: 1708

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.

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.

/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. 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).

  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. If someone can guide me towards that, then it will be great as well.

Upvotes: 4

Views: 2468

Answers (1)

Graham Dumpleton
Graham Dumpleton

Reputation: 58533

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

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.

For a big discussion of how Python should be installed properly on Linux systems go read:

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. That environment variable will allow mod_wsgi to find the correct library at run time and not use the version in /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. This is described in the documentation at:

Upvotes: 1

Related Questions