Posted: January 13th, 2010 | Author: Davo | Filed under: Django | Tags: apache, Django, httpd, mod_wsgi, wsgi | No Comments »
So what do we do next when we finished to develop(debug, debug… debug…!) our application? We go and deploy it of course!
Well, a common choice of deploying Django application is to use Apache httpd and mod_wsgi.
Let’s suppose the following scenario:
- our application name is marina
- our application is placed inside /home/ directory
- our static files (javascript, images, css etc…) are inside /home/marina/media/
The first step is to create the WSGI file and place it inside /home/marina/
With the following content:
03 | sys.path.append( '/home/' ) |
04 | sys.path.append( '/home/marina/' ) |
05 | os.environ[ 'DJANGO_SETTINGS_MODULE' ] = 'settings' |
06 | os.environ[ 'PYTHON_EGG_CACHE' ] = '/tmp' |
08 | import django.core.handlers.wsgi |
10 | application = django.core.handlers.wsgi.WSGIHandler() |
The second step is to edit your httpd.conf and add the following lines.
01 | <Directory "/home/marina/media" > |
06 | <Directory "/home/marina" > |
12 | Alias / media / / home / marina / media / |
13 | ServerAdmin admin@djangofoo.com |
14 | ErrorLog "logs/marina.com-error_log" |
15 | CustomLog "logs/marina.com-access_log" common |
18 | WSGIDaemonProcess marina user = daemon group = daemon processes = 2 threads = 25 |
19 | WSGIProcessGroup marina |
21 | WSGIScriptAlias / / home / marina / marina.wsgi |
We need to be sure that our folder is readable by the ‘daemon‘ user
1 | chown - R daemon / home / marina |
NOTE: if you are using /media/ to store all the static files be sure you have this inside your settings.py
1 | ADMIN_MEDIA_PREFIX = '/admin_media/' |
And finally don’t forget to restart your apache.
If you still have issues to run a Django application its worth checking the error logs.