Ubuntu 13.10 based Python/Django/WSGI setup

I am currently looking into the use of Django for one of my extra-curricular projects and needed to set up a development environment on Ubuntu. This is the log for future reference and hopefully useful for anybody needing to do the same.


Dependencies & Django Installation

Core Dependencies & Django

sudo apt-get install apache2 apache2-mpm-itk libapache2-mod-wsgi mysql-server python-django python-mysqldb

Optional add-ons

For my purposes I need a few more additional modules
sudo apt-get install python-networkx python-imaging python-pythonmagick python-markdown python-textile python-docutils python-pymongo

To test the installation you can check with this command that should print the Django version

python -c "import django; print(django.get_version())"

Django App Configuration

cd /home/USERNAME/projects/python
django-admin startproject djangotest
cd djangotest
python manage.py runserver

This should give something like the following as output:

Django version 1.5.4, using settings ‘djangotest.settings’
Development server is running at
Quit the server with CONTROL-C.

WSGI Configuration

All that remains to be configured is the Apache VHOST configuration containing the WSGI directives.

sudo vim /etc/apache2/sites-available/001-djangotest.conf

<VirtualHost *:80>
ServerName djangotest
ServerAdmin webmaster@domain.com
#<IfModule mpm_itk_module>
DocumentRoot /home/USERNAME/projects/python/djangotest
<Directory />
Options All
AllowOverride All
Require all granted
Alias /static/ /home/USERNAME/projects/python/djangotest/static/
<Location "/static/">
Options -Indexes
ErrorLog /home/USERNAME/projects/python/djangotest/apache/logs/error.log
CustomLog /home/USERNAME/projects/python/djangotest/apache/logs/access.log combined
WSGIScriptAlias / /home/USERNAME/projects/python/djangotest/djangotest/wsgi.py
WSGIDaemonProcess djangotest python-path=/home/USERNAME/projects/python/djangotest processes=2 threads=15 display-name=DjangoTest
WSGIProcessGroup djangotest

Lastly enable the site and restart Apache

sudo a2ensite 001-djangotest
sudo service apache2 restart

PLEASE NOTE: On Ubuntu 13.10 due to Apache being now 2.4 there is a fairly important change in access permissions (which cost me some time to work out) See: http://httpd.apache.org/docs/2.4/upgrading.html#access.
Also worth noting that the binary version of mod_wsgi is not compatible with the binary version of mod_itk (you will get an error like “Unable to connect to WSGI daemon process”) as WSGI tries to access the files using the default www-data user rather than the user assigned with using mod_itk. If you need this to work you will have to compile your own version of mpm_itk.

Author: Leo Gaggl

ict business owner specialising in mobile learning systems. interests: sustainability, internet of things, ict for development, open innovation, agriculture

One thought on “Ubuntu 13.10 based Python/Django/WSGI setup”

Leave a Reply