Ubuntu 13.10 based Python/Django/WSGI setup
By Leo Gaggl
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<br></br>django-admin startproject djangotest<br></br>cd djangotest<br></br>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 http://127.0.0.1:8000/
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><br></br>ServerName djangotest<br></br>ServerAdmin webmaster@domain.com<br></br>#<IfModule mpm_itk_module><br></br>#AssignUserID USERNAME USERNAME<br></br>#</IfModule><br></br>DocumentRoot /home/USERNAME/projects/python/djangotest<br></br><Directory /><br></br>Options All<br></br>AllowOverride All<br></br>Require all granted<br></br></Directory><br></br>Alias /static/ /home/USERNAME/projects/python/djangotest/static/<br></br><Location "/static/"><br></br>Options -Indexes<br></br></Location><br></br>ErrorLog /home/USERNAME/projects/python/djangotest/apache/logs/error.log<br></br>CustomLog /home/USERNAME/projects/python/djangotest/apache/logs/access.log combined<br></br>WSGIScriptAlias / /home/USERNAME/projects/python/djangotest/djangotest/wsgi.py<br></br>WSGIDaemonProcess djangotest python-path=/home/USERNAME/projects/python/djangotest processes=2 threads=15 display-name=DjangoTest<br></br>WSGIProcessGroup djangotest<br></br></VirtualHost>
Lastly enable the site and restart Apache
sudo a2ensite 001-djangotest<br></br>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.