4

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.

5
  • These are only warnings, and as the two versions are so close, you may simply ignore them. Commented Apr 10, 2016 at 13:38
  • Uh no those aren't just warning, those are the cause of later runtime errors. Because I do not know where did the version 2.7.10 come in, that version is not properly compiled pyUnicodeUCS4_AsEncodedString, which I took care of in my 2.7.11 installation. So yeah I do need to use the correct python version which I have installed in location /usr/local location Commented Apr 10, 2016 at 13:42
  • I was referring to: [wsgi:warn]. So you can really live with it. Of course that's the reason of the warning that if you'd use something which is different in these two versions, then you could have an issue. Chances are low. Commented Apr 10, 2016 at 13:46
  • @Zorgmorduk check the complete log here codeshare.io/cPRH0. The pyUnicodeUCS4_AsEncodedString error occurs because that unknown 2.7.10 version picked up by the apache server is not properly compiled for unicode 4 support. Commented Apr 10, 2016 at 13:47
  • Ahhh. I see. Then it's an issue indeed. Commented Apr 10, 2016 at 13:48

1 Answer 1

1

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:

Sign up to request clarification or add additional context in comments.

6 Comments

I already mentioned that the whole reason for using Python 2.7.11 for me is that I compiled it with unicode 4 support and thats what i used for compiling mod_wsgi as well, hence the error log shows correctly the line mod_wsgi: Compiled for Python/2.7.1. So till the point of compilation and installation of mod_wsgi everything is perfect, like you suggested. What baffles me is Python 2.7.10 because '/usr/local/bin/python is 2.7.11 with UCS4 flag and /usr/bin/python is 2.7.6 with UCS2. I have already mentioned this in my question.
I also tried using WGIPythonHome as suggested by you on your blog but that doesn't seems to be working with WSGIDaemonProcess. I even tried putting python-home=/usr/local within WSGIDaemonProcess as suggested but even that doesn't work, probably because the latest version of mod_wsgi 4.5.1 has discontinued that. The main scary point is the python version 2.7.10, it shouldn't even be there in the first place, I have no clue where it is coming from. It should have been 2.7.6 or 2.7.11 :|
ldd /usr/lib/apache2/modules/mod_wsgi.so gives /usr/local/lib/libpython2.7.so.1.0
mod_wsgi 4.5.1 has not discontinued the python-home option to WSGIDaemonProcess directive. The documentation isn't up to date if that is what you are relying on. Are you sure you aren't also loading mod_python into the same Apache.
What do you get if you run string /usr/local/lib/libpython2.7.so.1.0 | grep 2.7.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.