How install your own Django (dreamhost.com)
Written by Administrator   
Wednesday, 18 March 2009

Prepare

We’ll need to configure your Dreamhost account for use with Django. DreamHost  have FastCGI support.

  • Log into your DreamHost Web Admin Panel
  • Click on Domains / Manage Domains
  • Click Edit under the Web Hosting column for the domain that you wish to use with Django "mydomain.com"
  • Ensure that the FastCGI Support option is enabled. If not, click the box to enable it and then click Change "fully hosted settings now!"
  • Enable SSH access and request the default bash shell
For Windows (ssh client):
  • Free: WinSCP is an open source free SFTP client for Windows using SSH

Create a MySQL database

Need to setup a MySQL database to use with Django. Follow these steps:

  • In the Dreamhost administration panel, choose “manage MySQL” under the Goodies menu.
  • Enter a database name for your new database. I’ve chosen django_db and will be using that name in the tutorial.
  • Enter a hostname for your database server. 
  • Enter a username and password for your database.
  • Click the “Add new database now!” button.

Create a directories

  • SSH into your Dreamhost server.
  • Go your $HOME directory
  • Make a new directory for Django: mkdir django
  • Change into your new directory: cd django
  • Create directories for templates and projects: mkdir django_templates and mkdir django_projects
  • Create a directory to store your media files (css, images, javascript, etc.).

Download and Install

Using the latest Django by checking it out from its Subversion repository.

  • In your ~/django directory, check out the source: svn co http://code.djangoproject.com/svn/django/trunk/ django_src
  • Edit your ~/.bash_profile file, adding the following lines. This sets your Python path to include your Django directories, and puts Django’s utilities in your system path. You can edit the file however you like.
  • install: easy_install django_src
  • edit .bash_profile to add Django to your path and python path and other command:

export PATH=$PATH:$HOME/django_src/django/bin
export PYTHONPATH=$PYTHONPATH:$HOME/django_src:$HOME/django_projects

source .bash_profile

ln -s $HOME/django_src/django/contrib/admin/media $HOME/media.mydomain.com/admin_media

Start a Django project

Django differentiates between “projects” and “applications.” A project can contain multiple apps.

  • Move into your Django projects directory: cd ~/django/django_projects
  • Start a new project, using Django’s command line utility. This creates a basic directory structure for the project and adds the necessary configuration files: django-admin.py startproject myproject
  • Ensure that only you can read and write to the settings file for your project. This is very important, as your database password will be in this file: chmod 600 myproject/settings.py
  • Edit the myproject/settings.py file with our configuration parameters:
    • settings.py
      DATABASE_ENGINE = 'mysql'           
      DATABASE_NAME = 'django_db'
      DATABASE_USER = 'user'
      DATABASE_PASSWORD = '12345qwe'
      DATABASE_HOST = 'mysql.mydomain.com'
      TIME_ZONE = 'US/Pacific'
      MEDIA_ROOT = '/home/myuser/media.mydomain.com/'
      MEDIA_URL = 'http://media.mydomain.com/'
      ADMIN_MEDIA_PREFIX = 'http://media.mydomain.com/admin_media/'

configure FastCGI

cd ~/mydomain.com
wget http://svn.saddi.com/py-lib/trunk/fcgi.py
Edit ~/mydomain.com/dispatch.fcgi
#!/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()
 chmod 755 ~/mydomain.com/dispatch.fcgi ~/mydomain.com/fcgi.py
 Edit ~/mydomain.com/.htaccess
RewriteEngine On
RewriteBase /
RewriteRule ^(dispatch\.fcgi/.*)$ - [L]
RewriteRule ^(.*)$ dispatch.fcgi/$1 [L]
~/django_projects/myproject/manage.py syncdb
  • Load http://www.mydomain.com/ in a browser and you should see the "It worked!" page.
  • Edit ~/django_projects/myproject/urls.py and uncomment the admin lines.
  • Touch the dispatch.fcgi to reload the code
touch ~/mydomain.com/dispatch.fcgi
Load http://www.mydomain.com/admin/ in a browser and you should see the admin login page.
Last Updated ( Wednesday, 18 March 2009 )