Skip to content

Dreamhost Django Install, Revised Edition

by Jeff

I recently went back to doing some Django development after a long lapse, and decided to start by eating my own dogfood…

I started by upgrading Python for my Dreamhost user. I followed my own post, except that I used Python 2.6 instead of 2.5. I missed one step that was caught by a pingback post:

In addition to the steps I outlined before:

$ mkdir opt
$ mkdir downloads
$ cd downloads
$ wget http://www.python.org/ftp/python/2.6.4/Python-2.6.4.tgz
$ tar xvzf Python-2.6.4.tgz
$ cd Python-2.6.4
$ ./configure --prefix=$HOME/opt/ --enable-unicode=ucs4
$ make
$ make install

Next append

export PATH=$HOME/opt/bin/:$PATH

to your .bash_profile. Then test (from your home dir):

$ source .bash_profile
$ python -V
Python 2.6.4

If you don’t see Python 2.6.4 after typing python -V then you’ve already done something wrong.

I had to install the Python setuptools:

$ wget http://pypi.python.org/packages/2.6/s/setuptools/setuptools-0.6c9-py2.6.egg
$ sh setuptools-0.6c9-py2.6.egg

before installing Mysql-Python as before:

$ wget http://downloads.sourceforge.net/project/mysql-python/mysql-python-test/1.2.3c1/MySQL-python-1.2.3c1.tar.gz
$ tar xvzf MySQL-python-1.2.2.tar.gz
$ cd MySQL-python-1.2.2
$ python setup.py install

So this brought me to the point where I had an updated version of Python on my Dreamhost account.

Next to set up Django.

I looked at setting up Django with the Dreamhost script, which didn’t seem to work for me but I don’t remember why not. In the end I found SOASI’s post the most useful, although I did it a little differently.

First up, configure your domain.

In Dreamhost panel -> Domains -> Manage Domains click on the domain you want to put your app on (in the example we will set domain.com), and activate “Ruby on Rails Passenger (mod_rails)” option.

Create a public directory in that domain.

Next make sure you have your database setup. You don’t have to have a database for Django now, but if you plan to use one now is a good time to get that set up.

Next I downloaded and installed Django.

I liked the directory structure suggested by Dreamhost. This will work well for having one Django directory and use it for multiple projects on multiple domains.

 /home/username/django/
   source (your django svn checkout, or skip it and use Dreamhost's site-package of Django)
   projects
   applications (any reusable applications shared between projects)

Finally, I added the media and admin media, and also the passenger_wsgi.py

import sys, os
if sys.version < "2.6": os.execl("/home/user/opt/bin/python2.6", "python2.6", *sys.ar
gv)
sys.path.insert(1, "/home/user/django/source")
sys.path.insert(1, "/home/user/django/applications")
sys.path.insert(1, "/home/user/django/projects")
os.environ['DJANGO_SETTINGS_MODULE'] = "project.settings"
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()

On /home/user/django/projects/myproject/settings.py file check settings:

MEDIA_ROOT = '/home/user/domain.com/public/media/'
MEDIA_URL = 'http://www.domain.com/media/'
ADMIN_MEDIA_PREFIX = '/admin_media/'

Create a symbolic link for admin_media:

cd /home/user/domain.com/public/
ln -s home/user/django/source/contrib/admin/media/ admin_media

Django and Python are still new to me, so you get what you pay for with this setup.

Note:
I found this today, and it looks like it could be a good setup too.

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

2 Comments

  1. Leo Dirac wrote:

    Thanks for the detailed instructions. This is exactly what I needed!

    The steps leave out adding
    export PATH=$HOME/opt/bin/:$PATH
    to ~/.bashprofile and that you’re not in the right directory to source it. But that’s not the tricky part.

    Thanks!

    Wednesday, February 3, 2010 at 3:07 pm | Permalink
  2. Jeff wrote:

    Nice catch, Leo! I’ve updated the post.
    Thanks for commenting.

    Wednesday, February 3, 2010 at 10:31 pm | Permalink

Post a Comment

Your email is never published nor shared. Required fields are marked *
*
*