Pages

Monday 28 November 2011

Running Django on Fasthosts

Yes, you read that right. This post contains details of how to run Django application on Fasthsots.

You will need:

  1. A fasthosts linux hosting account with a MySQL database and SSH access, and with CGI enabled.
  2. A Centos 5.6 virtual machine to set everything up on.
On your new fresh Centos virtual machine, run the following:

yum install mysql-devel gcc

Download and extract the python source code:

wget http://python.org/ftp/python/2.7.2/Python-2.7.2.tgz
tar xzvf Python-2.7.2.tgz
cd Python-2.7.2

Configure, make and install python:

./configure
make
make install

Now install setuptools:

wget http://pypi.python.org/packages/source/s/setuptools/setuptools-0.6c11.tar.gz
tar xzvf setuptools-0.6c11.tar.gz
cd setuptools-0.6c11
python setup.py install

This will allow us to use easy_install to install pip and virtualenv

easy_install pip virtualenv

Right, now log in to fasthosts via SSH, and run

pwd

This is your home folder. Back on your Centos box, create a folder using the exact path pwd gave you on fasthosts:

mkdir -p <folder>
cd <folder>

Now create self-contained python environment:

virtualenv --distribute --no-site-packages django

Activate the virtual environment:

source django/bin/activate

And you should now be able to install any packages you need for your application to run.

pip install django MySQL-python

You will also need the standard python libraries:

cp -R /usr/local/lib/python2.7/* django/lib/python2.7/

Copy your Django project to the django folder and scp to the root of you home folder on fasthosts.

scp -r django <user>@<host>:./

You should now be able to ssh into fasthosts and run syncdb.

source django/bin/activate
cd django/<app name>
python manage.py syncdb

Copy any media files to htdocs/media and htdocs/static as required.

Finally, you need just two more files. This .htaccess in htdocs folder:

RewriteEngine on
RewriteRule ^cgi-bin/ - [L]
RewriteRule ^static/ - [L]
RewriteRule ^media/ - [L]
RewriteRule ^(.*)$ /cgi-bin/django.cgi/$1 [QSA,L]

The final file you need is django.cgi to go in your cgi-bin. Instructions of what you need to change can be found here: http://joemaller.com/1467/django-via-cgi-on-shared-hosting/

13 comments:

  1. Good. I am really impressed with your writing talents and also with the layout on your weblog. Appreciate, Is this a paid subject matter or did you customize it yourself? Either way keep up the nice quality writing, it is rare to peer a nice weblog like this one nowadays. Thank you, check also virtual edge and free online registration software

    ReplyDelete
  2. Wow.. Very informative article thanks for sharing please keep it up.. You can apply for an India tourist visa urgent in some case of emergency and you can also apply for an India visa super urgent, it takes less as compared to sticker visa.

    ReplyDelete
  3. It's very nice what you're sharing with your audience. I have read your article and I think it's very nice. You can apply for an super urgent visa India by clicking the link we just provided. Thanks for adding value to the post.

    ReplyDelete
  4. Hello, I am Albert. This is an excellent article blog, How to apply for India visa online? You can apply for an online e visa India 2022 within 5 to 10 minutes. You can get your India Visa within 3 to 5 business days. Read more information about Visa on our India Visa Blog

    ReplyDelete
  5. Beautiful blog and post! India visa from USA can be applied online via India e visa portal. And you can learn more info about Indian visas through our website.

    ReplyDelete
  6. The article you wrote is very interesting and easy to read and understand. I hope your audience enjoys it. Passengers who wish to visit Turkey and need a Turkey visa USA can apply online at the website linked above.

    ReplyDelete
  7. This comment has been removed by the author.

    ReplyDelete
  8. I go to your blog from time to time and guidance it to the all out of individuals who needed to feature on happening their perception coming about to ease. The approach to forming is faultless and notwithstanding the substance material is finish score. appreciation for that knowledge you give the perusers. Nord VPN Crack

    ReplyDelete