There was a problem loading the comments.

Django with fastcgi

Support Portal  »  Knowledgebase  »  Viewing Article

  Print

Django can be installed on a shared environment if you use FastCGI with it.

Note: You will need the FLUP module and Django installed. VPS and Dedicated plans can use these instructions, but shared and reseller plans already have these modules installed.

Here we go!

First, we need to install the flup module and django. We can use easy_install to do that.

Run these commands...

easy_install flup
easy_install django

No easy_install on your server?

  1. Go to http://pypi.python.org/pypi/setuptools#files and download the appropriate egg for your version of Python, i.e. setuptools-0.6c11-py2.4.egg. Do NOT rename it.
  2. Run it as if it were a shell script, i.e. sh setuptools-0.6c11-py2.4.egg . Setuptools will install itself using the matching version of Python (normally python2.4), and will place the easy_install executable in the default location for installing Python scripts.
  3. Go back to the top of this page and try the two easy_install lines, again.

Almost done!


Note: This next part can be done by any user who has SSH access. This means VPS, dedicated, shared, and reseller.

Create a new django project or upload your existing project (not shown). It might be a good idea to create a new dummy project just to have a baseline to test your installation.

To start a new project, run these commands...

django-admin.py startproject newproject
cd newproject
chmod +x manage.py
./manage.py startapp newapp


Note: These last parts can be done by anyone with access to a VPS, dedicated, shared, or reseller plan.

Create the file index.fcgi and place it inside your www directory (same as public_html) or the document root you desire. Change the file's permissions to 0755. Next, edit the file and enter this code:

#!/usr/bin/python
import sys, os

# Add a custom Python path. (optional)
sys.path.insert(0, "/home/username")

# Switch to the directory of your project.
os.chdir("/home/username/newproject")

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

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

The code above will work for anyone who literally followed the previous commands to install Django and create a new project. If you changed the project or directory names, you will need to make those same changes to the above code.

Finally, here are the .htaccess rewrite rules which belong in the same directory as your new index.fcgi file.

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

*All finished.*


Note: If you have more than one python installation, you may need to specify for which one you're installing setuptools. This seems to only be necessary for Resellers.

Here's how to fix the problem from SSH:

wget http://peak.telecommunity.com/dist/ez_setup.py
/usr/bin/python ez_setup.py
/usr/bin/easy_install django flup==1.0.2

WGET is not enabled by default, so you will need to contact Osirion at least once and request for us to enable WGET.


Share via
Did you find this article useful?  

Related Articles


Comments

Add Comment

Replying to  

CAPTCHA
© Osirion System Technologies