Skip to content

Home > GNU/Linux > How to deploy recent django on an old Ubuntu Lucid Lynx installation

How to deploy recent django on an old Ubuntu Lucid Lynx installation

Get the correct python version !

Thursday 18 June 2015, by Stéphane Téletchéa

Nowadays it is sometimes difficult to upgrade a wroking web server, when multiple services are installed. In order to keep up with some recent versions, here is a short guide to get django 1.8.1 working with Ubuntu Lucid Lynx and apache 2.2.

In order to ensure the compability between the development server (Ubuntu 14.04 LTS 64 bits) and the production server, we have to compile python first. We will not require super-user powers to install most of the applications :-)

Install latest python version

wget https://www.python.org/ftp/python/2.7.10/Python-2.7.10.tar.xz
tar -Jxf Python-2.7.10.tar.xz
cd /Python-2.7.10
./configure —enable-shared —prefix=DESTINATION/python2.7.10/
make
make install

Remark: replace DESTINATION with your home directory or any directory where you have write access.

Recompile mod_wsgi

cd /mod_wsgi-stable-3.X
export LD_RUN_PATH=DESTINATION/python2.7.10/lib/
export LD_LIBRARY_PATH=DESTINATION/python2.7.10/lib/
./configure —with-python=DESTINATION/python2.7.10/bin/python2.7
make

Remark: both LD_RUN_PATH and LD_LIBRARY_PATH are mandatory otherwise the compilation and/or the execution within apache will fail.

Ensure the library is properly compiled with the correct python version:

ldd .libs/mod_wsgi.so
        linux-vdso.so.1 =>  (0x00007ffffa3ff000)

        libpython2.7.so.1.0 => DESTINATION/python2.7.10/lib/libpython2.7.so.1.0 (0x00007facf1790000)

        libpthread.so.0 => /lib/libpthread.so.0 (0x00007facf156a000)
        libdl.so.2 => /lib/libdl.so.2 (0x00007facf1365000)
        libutil.so.1 => /lib/libutil.so.1 (0x00007facf1162000)
        libm.so.6 => /lib/libm.so.6 (0x00007facf0edf000)
        libc.so.6 => /lib/libc.so.6 (0x00007facf0b55000)
        /lib64/ld-linux-x86-64.so.2 (0x00007facf1d99000)

Remove old apache modules before installing the new one

apt-get remove —purge libapache2-mod-wsgi libapache2-mod-python

Remark: you have to remove both mod-wsgi and mod-python since mod-wsgi supersedes mod-python, ans apache can not handle two different python versions while running (you may run into trouble).

Install the new mod_wsgi and restart apache

Only for these steps, you need to be root (or ask the root to do so).

cd DESTINATION/mod_wsgi-stable-3.X
make install

Then activate the new wsgi apache module, and restart apache:

a2enmod wsgi
service apache2 restart

Remark: You HAVE TO restart apache, a simple reload will not be sufficient to have running modules removed or replaced.

If everything worked properly, you can see in apache2/error.log the python2.7.10 indicated:

Before:

Apache/2.2.14 (Ubuntu) mod_python/3.3.1 Python/2.6.5 ... mod_wsgi/3.5 ...

After:

Apache/2.2.14 (Ubuntu) mod_wsgi/3.5 Python/2.7.10 ...

Install latest django with virtualenv

Install lastest virtualenv

virtualenv 1_old_venv —no-site-packages
source 1_old_venv/bin/activate
pip install —upgrade virtualenv
deactivate

Install lastest a new virtualenv with latest python

source 1_old_venv/bin/activate
virtualenv —python=DESTINATION/python2.7.10/bin/python django1.8 —no-site-packages
deactivate
source django1.8/bin/activate

Then proceed to install all your requirements

(django1.8) pip install Django==1.8.1
(django1.8) pip install django-extension==1.5.2
(django1.8) pip install MySQL-python==1.2.5
...

You have now a fully functional django module that you can incoporate into you existing apache configuration using WSGIDaemonProcess.

Useful informations

Comment on this article