Deploying Django in Apache using mod_wsgi
Deploying Django in Apache using mod_wsgi is the most recommended one when compared to using mod_python. Deploying Django in apache is not very difficult, its simple with quite simple steps. Here i have created a helloworld project and explained how to deploy it in apache. You must install mod_wsgi apache module before trying this.
Step 1: Create an directory named apache in your project directory. And add two files one for conf and another a wsgi application in it.
$mkdir apache
$cd apache
$touch apache_django_wsgi.conf
$touch dj_hello.wsgi
Step 2: Open the apache_django_wsgi.conf file with a text editor(gedit)and add the following contents
WSGIScriptAlias /dj “/path/to/us/project/folder/helloworld/apache/dj_hello.wsgi”
<Directory “/path/to/ur/project/folder/helloworld/apache”>
Allow from all
</Directory>
Here, helloworld is the name of the project
Step 3: Open the dj_hello.wsgi with a text editor(gedit) and add the following contents
import os, sys
#Calculate the path based on the location of the WSGI script.
apache_configuration= os.path.dirname(__file__)
project = os.path.dirname(apache_configuration)
workspace = os.path.dirname(project)
sys.path.append(workspace)
#Add the path to 3rd party django application and to django itself.
sys.path.append(‘/usr/lib/python2.5/site-packages/django/’)
os.environ['DJANGO_SETTINGS_MODULE'] = ‘helloworld.settings’
# project settings file
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
Step 4: Put an entry in your apache configuration fine (httpd.conf or apache2.conf depending upon the destro you are using)
Include “/path/to/ur/project/folder/helloworld/apache/apache_django_wsgi.conf”
helloworld, is the name of the django project that i am deploying in django. After doing all the steps don’t forget to restart the apache service for the changes to take effect.





