Running Django under a Shared Hosting Environment

I’ve been developing with Django on my local machine,
and I was wondering if there was a way for me to
deploy it on a shared hosting server,
after playing around with it for a few hours, it actually works!

I’m quite surprised so much is possible without having root access (installing Python, Pip & Django).

You will need SSH access though, but most decent hosts give that nowadays.
The 3 steps you have to go through are:

You download the source code, and do the old ./configure, make , make install.
the only difference is that (because you have no root access) you have to install into your local directory, by using:

./configure -prefix=/home/directory/...

and then

make install

You also have to add Python to your Path by writing

you should also add this to your /home/directory/.bashrc (the file should already exist)
so that command will run once your session starts.

just download pip here
and install via

python install

try writing

pip install Django 

and if you want some MySQL support:

pip install MySQL-python

for some reason, the installation of django didn’t work for me, so I
simply downloaded django and
copied the folder “django” (ignoring the other folders “docs” “extras” “scripts” and “tests” alltogether) into my
“site-packages” folder (should be located wherever you installed your python)

Worked just fine.

Then I created a Django project via going to /home/directory/djangoproject (new directory): startproject djangoproject

(notice that this is not inside the www (or public_html) folder!)
Now for the last (and trickiest) part:

Django on Apache
Inside the www folder, I created a subfolder called “djangoproject” (the name doesn’t really matter)
and inside created 2 files:

import sys, os

sys.path.insert(0, "/home/directory/python/python27/site-packages")
sys.path.insert(13, "/home/directory/djangoproject")

os.environ['DJANGO_SETTINGS_MODULE'] = 'djangoproject.settings'
from django.core.servers.fastcgi import runfastcgi
runfastcgi(method="threaded", daemonize="false")

and .htaccess file that contains:

AddHandler fcgid-script .fcgi
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ djangoproject.fcgi/$1 [QSA,L]

After that I accessed the folder, and Voilà !

For more information, I highly recommend this blog post


If you’re having some issues that you can’t figure out with Apache, try running the djangoproject.fcgi file directly via:


this will give you more clues as to what went wrong (python problem, permissions, etc.)

Update 2

Sometimes, changes within the .fcgi file are not taken by apache until you restart it.

Tagged with: , , , ,
Posted in Technology
Welcome to KidsIL
A blog for Technology, Brainstorming & Berlin!

Take a look at StartCast.
A podcast with the sole purpose of interviewing co-founders of Startups in Europe & around the world.

You should try Berlin On Feier, an App I built for finding the best parties in Berlin.