I am in the process of migrating all my websites from Pair hosting to Dreamhost. I managed to get a deal from Dreamhost that I couldn’t refuse, and I’ve been meaning to redesign some of my projects on top of the Django framework, so the switch made sense.
Setting up Django projects on Dreamhost isn’t completely painless, however. The wiki article is very helpful, but if you’re a Django newbie like myself you may get hung up on a few things (like I did). The following is a short tutorial on how to get up and running with Django, with hosting from Dreamhost.
Getting ready
Enable FastCGI in your Dreamhost Web Panel under Domains » Manage Domains » (click the domain to be Django-ified):

Here is where you want to enable FastCGI
Create a “media” subdomain under Domains » Manage Domains (ex: media.<yourdomain>.com). The media subdomain is where all of your static media files (like images or CSS files) are located. To use these in your Django templates hard-link to the location of the media subdomain (don’t worry we’ll get to this later).
SSH into your Dreamhost server and create a projects directory in your home folder.
mkdir django_projects
Getting and Installing Django
Once you have set up your environment you’re ready to go. Get the most recent stable release of Django’s source code through SVN:
svn co http://code.djangoproject.com/svn/django/trunk/ django_src
This grabs the current release of the Django source code and checks out a working copy to a newly created directory “django_src”. Next we must “install” Django by adding it’s script locations to our PATH variable. The PATH variable is checked by your shell every time you invoke a command (ex “ls” or “mkdir”). Once we add the Django scripts to our PATH we can execute them in our shell. To do this use your favourite text editor to open up ~/.bash_profile. Add the following lines at the bottom of the file:
export PATH=$PATH:$HOME/django_src/django/bin
export PYTHONPATH=$PYTHONPATH:$HOME/django_src:$HOME/django_projects
Now that we have included the new directories in our PATH (and our PYTHONPATH, Python’s own special PATH variable), you must update your current shell session to reflect the changes. To do this either close and reopen your shell session, or just type:
source ~/.bash_profile
Creating your Django project
The next step is to actually start and configure our Django project! To do this navigate to your django_projects directory created earlier, and start your Django project (replace “myproject” with your new project’s intended directory name:
cd ~/django_projects
python django-admin.py startproject myproject
chmod 600 myproject/settings.py
Writing an FCGI Dispatcher
Inside of the directory where your website lives, download this handy FCGI dispatched script written by a generous member of the Dreamhost community:
cd ~/[your domain]
wget http://svn.saddi.com/py-lib/trunk/fcgi.py
Create a new file called “dispatch.fcgi” and fill it with the following:
#!/usr/bin/python2.4
import sys
sys.path += ['/home/myuser/django_src']
sys.path += ['/home/myuser/django_projects']
from fcgi import WSGIServer
from django.core.handlers.wsgi import WSGIHandler
import os
os.environ['DJANGO_SETTINGS_MODULE'] = 'myproject.settings'
WSGIServer(WSGIHandler()).run()
Make sure you change the paths to be the directories you defined earlier! This is very important. Next make the newly created files executable:
chmod 755 ~/mydomain.com/dispatch.fcgi ~/mydomain.com/fcgi.py
Make yourself an .htaccess file
Edit ~/[your domain]/.htaccess and add the following:
RewriteEngine On
RewriteBase /
RewriteRule ^(dispatch\.fcgi/.*)$ - [L]
RewriteRule ^(.*)$ dispatch.fcgi/$1 [L]
Initialize your Django project’s database:
~/django_projects/myproject/manage.py syncdb
Now you should be able to point your browser to www.<your domain>.com and see the “It worked!” page. You’re all set with your new Django-powered host.