2011 Installation Instructions for Django on Bluehost

Most of this was gleaned from squinting hard at the below:


But some stuff has changed due to Bluehost’s recent implementation of OpenSSH. So here goes!

This tutorial assumes you already have Python2.6 installed on Bluehost. (This should come with your hosting plan)

First things first– SSH into your account (using Putty, for instance). In order to do this you will have to enable SSH in your cPanel and send identification to Bluehost. Putty will prompt you for your password.

You are now in the home directory. Move into the directory where you would like to install Django from. Despite what the Bluehost instructions say, it doesn’t matter where this is. I just downloaded Django into my home directory.

cd ~
wget http://www.djangoproject.com/download/1.2.4/tarball/
tar xzvf Django-1.2.4.tar.gz
cd Django-1.2.4

Now you can try installing:

python2.6 setup.py install --user

The below may or may not affect anything. Bluehost seems to have disabled the .bashrc in your home directory (not the one in your etc folder, that one is read-only) But go ahead and do it anyway just in case.

Django installs some commands that you can use in your bash shell. To make sure
these work, add the following to the end of your .bashrc file:

export PATH=$HOME/.local/bin:$HOME/.local/usr/bin:$PATH

Log out and log back in to effect this change.


Now you’ll want to confirm that django can run in Python. From the official bluehost instructions:

Testing Your Installation

You can test your installation of Django to see if it worked by starting the
Python interpretor by typing python2.6 at the command prompt and hitting
enter. You’ll get the Python interactive interpretor, where you can type
import django and hit enter. If it gives an error, then there is a problem
with your installation. If no error is given, then you’ve successfully
installed Django to your Python path. Go ahead and exit the Python shell by
typing ctrl+d.

If you were unable to import Django, try re-logging in to your shell, and try
again. If it still doesn’t work, double check to make sure that your Python
path is correct, and that Django really resides in a directory on the Python
Path. To see what this list of directories is, start up the Python interpretor,
and type “import sys; sys.path“, and press enter. This should give you a
list of directories. This should include any directories you listed in your

.bashrc file for PYTHONPATH. Check for any typos in your .bashrc
file. As long as the django directory is in one of those directories
listed, then you should be able to do the import. If it isn’t in any of those
directories, try re-installing Django.

You’ll also want to test the django-admin.py command by trying to run it
from your shell. You should get a usage message with a list of management
commands that can be run. If you get “command not found”, then there was a
problem with the installation of Django
This will probably not work. When you call django-admin.py you will have to do it with an absolute path. Something like,

python2.6 ~/.local/bin/django-admin.py

If django-admin.py isn’t in that directory, try re-installing Django.


Decide where you want to put your django projects. You can put them anywhere, but for security’s sake, they should not be in public_html or any of its subdirectories.

Let’s say you decide on “django_projects”, and you want it to be in your home directory. And let’s say your bluehost username is DJANGONOOB. and let´s say your first project name will be “myFirstProject

cd ~

mkdir django_projects

cd django_projects

initialize your project:

python2.6 /home/DJANGONOOB/.local/bin/django-admin.py startproject myFirstProject

Once the project directory has been created, cd into it

cd myFirstProject

and then follow the tutorial part ONE here:

http://docs.djangoproject.com/en/dev/intro/tutorial01/ BUT keep the following in mind:

When you are creating the database, use sqlite3.

Remember that EVERYWHERE it says python, you must type python2.6 instead.

Everywhere you edit a file, use VIM editor, like so:

vi filename.py

This will bring up the editor. Press i to edit, and escape to exit editing mode.
After pressing escape, type :q! to quit without saving, and :wq to save and quit.

At the end of part one, you will have made a number of modifications. Make sure all your files match up with the below. You will have to change a few paths to make sure this works on Bluehost (changes are highlighted in red below)


# Django settings for testRun project.

DEBUG = True

    # ('Your Name', 'your_email@domain.com'),


    'default': {
        'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
        'NAME': '/home/DJANGONOOB/django_projects/testRun/testRunDB', # Absolute path to database file if using sqlite3.
        'USER': '',                      # Not used with sqlite3.
        'PASSWORD': '',                  # Not used with sqlite3.
        'HOST': '',                      # Set to empty string for localhost. Not used with sqlite3.
        'PORT': '',                      # Set to empty string for default. Not used with sqlite3.

# Local time zone for this installation. Choices can be found here:
# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
# although not all choices may be available on all operating systems.
# On Unix systems, a value of None will cause Django to use the same
# timezone as the operating system.
# If running in a Windows environment this must be set to the same as your
# system time zone.
TIME_ZONE = 'America/Chicago'

# Language code for this installation. All choices can be found here:
# http://www.i18nguy.com/unicode/language-identifiers.html


# If you set this to False, Django will make some optimizations so as not
# to load the internationalization machinery.
USE_I18N = True

# If you set this to False, Django will not format dates, numbers and
# calendars according to the current locale
USE_L10N = True

# Absolute filesystem path to the directory that will hold user-uploaded files.
# Example: "/home/media/media.lawrence.com/"

# URL that handles the media served from MEDIA_ROOT. Make sure to use a
# trailing slash if there is a path component (optional in other cases).
# Examples: "http://media.lawrence.com", "http://example.com/media/"

# URL prefix for admin media -- CSS, JavaScript and images. Make sure to use a
# trailing slash.
# Examples: "http://foo.com/media/", "/media/".

# Make this unique, and don't share it with anybody.
SECRET_KEY = 'a_i1wck_739wiot-ps995ua%g9*)i(z99)-uyz4sc$j3y)1_ja'

# List of callables that know how to import templates from various sources.
#     'django.template.loaders.eggs.Loader',



    # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
    # Always use forward slashes, even on Windows.
    # Don't forget to use absolute paths, not relative paths.

    # Uncomment the next line to enable the admin:
    # Uncomment the next line to enable admin documentation:
    # 'django.contrib.admindocs',


from django.conf.urls.defaults import *

# Uncomment the next two lines to enable the admin:
from django.contrib import admin

urlpatterns = patterns('',
    # Example:
    # (r'^mysite/', include('mysite.foo.urls')),

    # Uncomment the admin/doc line below to enable admin documentation:
    # (r'^admin/doc/', include('django.contrib.admindocs.urls')),

    # Uncomment the next line to enable the admin:
    (r'^admin/', include(admin.site.urls)),
    #(r'^polls/$', 'polls.views.index'),
\d+)/$', 'polls.views.detail'),
\d+)/results/$', 'polls.views.results'),
\d+)/vote/$', 'polls.views.vote')

Now for the big guns. Obviously you won’t be able to run all this on your browser as if you are running all this from an installation on your home computer.
It’s a server for god’s sake. So you’ll have to get into some fun redirecting.

Decide where you want the project to be in your viewable directory structure. So, say you want your project to be accessible from:


then you would go

mkdir ~/public_html/django/testProject

cd ~/public_html/django/testProject

and now you’ll have to make a Fast CGI file to run your django site.

vim mySite.fcgi

copy and paste the following:

import sys, os

# Add a custom Python path.
sys.path.insert(0, "/home/DJANGONOOB/.local/lib/python2.6")
sys.path.insert(13, "/home/DJANGONOOB/django_projects/myFirstProject")

# Switch to the directory of your project. (Optional.)
# os.chdir("/home/DJANGONOOB/django_projects/myFirstProject")

# Set the DJANGO_SETTINGS_MODULE environment variable.
os.environ['DJANGO_SETTINGS_MODULE'] = "settings"

from django.core.servers.fastcgi import runfastcgi
runfastcgi(method="threaded", daemonize="false")

remember to :wq to save.

you must create an .htaccess to make sure mySite.fcgi is run when you pull this up in the browser:

vi .htaccess

copy and paste the below:

AddHandler fcgid-script .fcgi
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ mysite.fcgi/$1 [QSA,L]

now set the correct permissions for mySite.fcgi

chmod 0755 mySite.fcgi

now just pull up http://djangoNoob.com/django/testProject/admin/

and you should see the Django administration console!

Finally, I’m sure to have missed something. I tried I really did but I am trying to document 24 hours of jiggering here… so if it doesnt work for you please pipe up in the comments and I will help figure it out!

If you are interested in finding good django hosting, take a look at Webfaction. They are a one-click setup django hosting provider, and offer a lot of other really good features for advanced users.

11 Responses to “2011 Installation Instructions for Django on Bluehost”

  1. sec says:

    Hi, I just followed ur steps to setup django on bluehost. But I didn’t get the admin console work. I got the 500 error. and searched a lot on google and still have no idea….
    Could you please share something details by email?
    Thanks a lot! :)

  2. Ryan says:

    Bluehost is using the .bashrc file fine for me.

    Adding these two lines to the .bashrc file makes things a little nicer

    alias python=”python2.6″
    alias django-admin=”python2.6 ~/.local/bin/django-admin.py”

    Now you can just use “python” and “django-admin” everywhere :)

  3. Steve Young says:

    Thanks for a great job. I started with the instructions on bluehost’s site but got stuck and then ran across this and I have django installed!

    Ryan’s alias’ worked for me also.

  4. Steve Young says:

    When I bring up the admin page it does not show any of the css/formatting. I have tried several suggestions around the web, but no success. Can you remember what you did to make the ..django/contrib/admin/media files serve up properly?

  5. admin says:

    Hi Steve, glad you found the tut useful. I had a lot of problems with the admin media files myself. basically u need to copy django’s media folder (on your server, the path to it would be something like: ~/.local/lib/python2.6/site-packages/django/contrib/admin/media) to a subdirectory of public_html. Let’s say you copy it into “public_html/project_name/media”. Now in your project’s settings.py, you need to change the following setting to that path:

    ADMIN_MEDIA_PREFIX = “/project_name/media/”

    I think now django will load up everything correctly. let me know if this doesn’t help though, it might be a hack on my part… how django handles serving media is not my strong suit :/

  6. Steve Young says:

    Thanks so much. At first I was trying to use symlinks instead of copying the ../admin/media folder. Then I took your advice and copied the files – but I mistakenly copied them to the real django_project folder, not the url in public_html – so another few minutes scratching my head until I realized what I did. After moving the files to the correct directory and pointing ADMIN_MEDIA_PREFIX to the right location it works perfectly! Thanks so much.

    This has me thinking, does this apply to any static files I have in my app also? (Haven’t started to move my app yet…)

  7. David says:

    This is a great tutorial, but I’m having a problem during the Django installation. During the install_lib portion, I’m getting “error: could not create ‘/usr/lib/python2.4/site-packages/django’: Read-only file system”. Any idea how I can get around this with Bluehost?

  8. George says:

    David, I got the same error at some point. You probably forgot to add the “–user” at the end.

    python2.6 setup.py install –user

  9. Thank you so much. This helped me enormously.

  10. Julie says:

    Hi, I created a django site on my computer using python 2.7.1 and django 1.3.1. Should I still download django 1.2.4 to bluehost as suggested in this tutorial, or should I download django 1.3.1 as it’s the version I’ve used for my site?

  11. pramod says:

    Thanku very much

Leave a Reply

Your email address will not be published. Required fields are marked *

This blog is kept spam free by WP-SpamFree.

Get Adobe Flash player