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.
- Installing Python: Download the latest release of Python and unpack the compressed archive.
wget http://python.org/ftp/python/2.6.7/Python-2.6.7.tgz<br> tar zxf Python-2.6.7.tgz<br> cd Python-2.6.7.tgz ./configure --prefix=$HOME --enable-unicode=ucs4 make make install export PATH=~/bin:$PATH
Done! Python should be installed on your home folder.
Installing setuptools: Setup Tools is needed for installing more packages. So its better we set it up now.
wget http://cheeseshop.python.org/packages/2.4/s/setuptools/setuptools-0.6c5-py2.4.egg chmod +x setuptools* ./setuptools*
- Installing MYSQL-Python: This is needed for mysql connection for the django.
wget http://easynews.dl.sourceforge.net/sourceforge/mysql-python/MySQL-python-1.2.1_p2.tar.gz tar zxf MySQL-python-1.2.1_p2.tar.gz cd MySQL-python-1.2.1_p2 python setup.py build python setup.py install
- Installing FCGI: FCGI is needed for the Apache to use Django to serve the pages.
- On the panel configure your site for “Fast CGI Support?” found under (Domains->Manage Domains)-(yourdomain.com->Edit)->PHP Support
- Download the fcgi.py, placing it somewhere in your PYTHONPATH:
wget http://labs.sriunplugged.com/static/fcgi.txt mv fcgi.txt fcgi.py mv fcgi.py /home/rsrijith/opt/lib/python2.6/site-packages/
- Install Django: Next step is the installing of django. Download the code from the django projects and install it using the custom python.
wget http://www.djangoproject.com/download/1.3/tarball/ tar xzvf Django-1.3.tar.gz cd Django-1.3 sudo python setup.py install
Create a folder django and move django_src to that folder for future use.
mkdir django mv Django-1.3 django/django_src
- 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.
- 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
#!/home/<username>/opt/bin/python 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.