It took me an entire day, yes it did! I went here : http://wiki.site5.com/Python/Django/Django_installer. Browsed the forums. No help! Then I started on my own. I noticed that virtual python is loading the modules from the main python lib (/usr/lib/python2.4) instead of the local copy. I imported sys and read the sys.modules list. It pretty much made sense. If python doesn’t run locally (inside the virtual environment), it will try to install easy_install into the server wide path. You can’t achieve that unless you’re the root.
While looking for an alternative, I found virtualenv. It not only worked, it also shipped with a built in easy_install.
Later, when I set things up, I noticed that my app was breaking because Python wasn’t elegant enough to let use codes like this:
1 |
x = 34 if 23 > 22 else 78 |
Huh! I had to browse the django svn and try all the versions before I got it working. It was a tiring process, but I learned a lot of things! Here’s a quick tutorial for fellow Site5 users:
1) Get Virtualenv from here: http://pypi.python.org/pypi/virtualenv
1 2 |
cd ~ wget http://pypi.python.org/packages/source/v/virtualenv/virtualenv-1.5.1.tar.gz#md5=3daa1f449d5d2ee03099484cecb1c2b7 |
2) Run this command:
1 2 |
cd ~ python virtualenv.py ~ |
3) The above command will create a virtual python environment for you in “~/bin”. You can now run Python and easy_install by typing:
1 2 |
~/bin/python ~/bin/easy_install |
4) Now get MySQL bindings for Python and the flup package for the FCGI dark spells 😉
1 2 |
~/bin/easy_install MySQL-python ~/bin/easy_install flup |
5) Now we are ready to rock and roll with Django! Remember, Site5 has Python 2.4. The latest builds of Django might break. Please use the one I used in the following script:
1 2 |
cd ~ svn co http://code.djangoproject.com/svn/django/branches/releases/1.0.X/ django-src |
6) Create some Symlinks:
1 2 |
ln -s ~/django-src/django/ ~/lib/python2.4/site-packages/django ln -s ~/django-src/django/bin/django-admin.py bin/ |
7) Create a dedicated directory for django projects:
1 |
mkdir django |
8 ) Lets create a project and an app:
1 2 3 4 |
cd ~/django ~/bin/django-admin.py startproject mysite cd ~/django/mysite ~/bin/django-admin.py startapp myapp |
9) Create django.fcgi with the following content:
1 2 3 4 5 6 7 8 9 10 11 |
#!/home/masnunco/bin/python import sys, os # Add a custom Python path. sys.path.insert(0, "/home/masnunco/django") # the directory for django projects # Set the DJANGO_SETTINGS_MODULE environment variable. os.environ['DJANGO_SETTINGS_MODULE'] = "mysite.settings" # remember the project name? from django.core.servers.fastcgi import runfastcgi runfastcgi(method="threaded", daemonize="false") |
10) Lets finish with a .htaccess to finish it off, should we? 🙂
1 2 3 4 5 6 7 8 |
AddHandler fcgid-script .fcgi Options +FollowSymLinks RewriteEngine On RewriteBase / RewriteRule ^(media/.*)$ - [L] RewriteCond %{REQUEST_URI} !(django.fcgi) RewriteRule ^(.*)$ django.fcgi/$1 [L] |
3 replies on “Running django on Site5”
Great post man. Not sure why you don’t have more traffic. This saved me. Not sure why the SITE 5 folks can’t come up with a decent tutorial or guide for this. Really disappointing.
Probably obvious to those familiar with .tar.gz files and virtual envs, but I had to:
tar -xzf virtualenv-1.5.1.tar.gz
Before I could run python virtualenv.py ~ in step 2.
Stuck on step 5. Django doesn’t use subversion anymore and couldn’t get to work with github. Moving on to this tutorial, hope it works. http://www.codekoala.com/posts/installing-django-shared-hosting-site5/ Anyone get this working with site5? Site5’s docs are horrible with both the Django and Django in a virual env tutorials not working and syntax errors throughout.