Installing Django on Dreamhost

Installing Django in Dreamhost and getting it to run wasn’t straight forward at-least to me. There was lot of issues such as python bin directory not accessible as its shared and so.

So the initial step in this to setup python yourself so that you can use the bin folder and insert or edit any files needed.

  1. Installing Python: Download the latest release of Python and unpack the compressed archive.
    tar zxf Python-2.6.7.tgz<br>
    cd Python-2.6.7.tgz
    ./configure --prefix=$HOME --enable-unicode=ucs4
    make install
    export PATH=~/bin:$PATH

    Done! Python should be installed on your home folder.

  2. Installing setuptools: Setup Tools is needed for installing more packages. So its better we set it up now.

    chmod +x setuptools*
  3. Installing MYSQL-Python: This is needed for mysql connection for the django.
    tar zxf MySQL-python-1.2.1_p2.tar.gz
    cd MySQL-python-1.2.1_p2
    python build
    python install
  4. Installing FCGI: FCGI is needed for the Apache to use Django to serve the pages.
    1. On the panel configure your site for “Fast CGI Support?” found under (Domains->Manage Domains)-(>Edit)->PHP Support
    2. Download the, placing it somewhere in your PYTHONPATH:
      mv fcgi.txt
      mv /home/rsrijith/opt/lib/python2.6/site-packages/
    3. Install Django: Next step is the installing of django. Download the code from the django projects and install it using the custom python.
      tar xzvf Django-1.3.tar.gz
      cd Django-1.3
      sudo python install

      Create a folder django and move django_src to that folder for future use.

      mkdir django
      mv Django-1.3 django/django_src
    4. Setting up Site in DJango: Now that installing of django is done. Create a folder for projects called django_projects.
      cd django
      mkdir django/django_projects

      I assume you know how to create app and projects inside else refer to django projects site.

    5. Get the site running: Next is getting the actual domain or sub-domain up and running. Create the sub domain or domain to get the site created. Next move to that sub domain or domain folder. Create a file dispatch.fcgi in the base folder of that sub domain and insert the following code
      import os
      import sys
      from django.core.servers.fastcgi import runfastcgi
      sys.path += ['/home/<username>/opt/bin/python']
      sys.path += ['/home/<username>/django/django_projects/']
      sys.path += ['/home/<username>/django/django_projects/current/']
      os.environ['DJANGO_SETTINGS_MODULE'] = '<project_name>.settings'
      runfastcgi(['method=threaded', 'daemonize=false'])

      Next create a .htaccess file in the same folder to redirect all traffic coming to that domain to the fcgi file.

      RewriteEngine On
      RewriteBase /
      RewriteRule ^(dispatch.fcgi/.*)$ - [L]
      RewriteRule ^(.*)$ dispatch.fcgi/$1 [L]

    And you are done. I hope it works it took me some time to figure out some issues and fix it. If you get 5xx error check your permissions of the files. I hope you don’t get into the trouble I have been through. I compiled this from multiple websites. Some worked and some didn’t that’s why I felt I needed to combine all the things that worked into one blog. Tell me how it worked for me though comments.

, , , , , , , ,

  1. #1 by Dhruv on June 1, 2013 - 10:38 pm

    Thank you for the in-depth tutorial on django installation on DreamHost but this seems like a very lengthy process. One can easily install it using virtual python install. Please find more information on it at .

(will not be published)