nedeľa 6. septembra 2009

Deployment of the Django project using Apache2 and mod_wsgi on Ubuntu Linux

After several hours of pain when trying to have Apache+mod_wsgi+Django working on Mac OS X (Leopard), I decided to try Ubuntu Linux 9.04.

Prerequisities installed:

Python is installed by default, Django installation is pretty straightforward, just follow its official documentation. To see, how to install psycopg2, look at this how to. PostgreSQL installation is also pretty straightforward.


The installation itself:

sudo apt-get install libapache2-mod-wsgi

This command will install not only mod_wsgi, but also Apache2 webserver.


Webserver configuration:

Starting point:
http://docs.djangoproject.com/en/dev/howto/deployment/modwsgi/

What does that mean in shortness?
  1. Create apache/django.wsgi in your project directory as recommended.
  2. Add line with WSGIScriptAlias (for Django code) and AliasMatch (for CSS) directive into /etc/apache2/conf.d/security (included from /etc/apache2/apache2.conf) pointing to your apache/django.wsgi.
  3. Restart webserver: sudo /etc/init.d/apache2 restart.
  4. Test it accessing localhost via HTTP (http://localhost/admin or http://localhost).
What is my exact configuration? (example)

Contents of /home/django/DSBIS/apache/django.wsgi:


import os
import sys
os.environ['DJANGO_SETTINGS_MODULE'] = 'DSBIS.settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
sys.path.append('/home/django')


Contents of /etc/apache2/conf.d/security:



It's working.

Further reading:
http://docs.djangoproject.com/en/dev/howto/deployment/
http://djangobook.com/en/2.0/chapter12/

NOTE: This configuration of Apache is not final, I did further changes, but it will be subject of another article on this blog.

Žiadne komentáre:

Zverejnenie komentára

Archív blogu