Note: This information may be out of date. If you have experience with Django FastCGI support, please provide an update
I almost have
Django∞ working on my tiny shared account. Actually, I think it works right, but I don't have the rewrite rules correct and that's causing the problem. Anyway, I'll step you through what I have so far.
First of all, you need to make sure you have
Python2.3 for FCGI (and I think Django) to work. For more details about getting fcgi working, see
this thread∞. You also need to have shell access. If you don't, submit a ticket to ASO support.
First, open your shell and confirm your version of Python (be sure to use a Capital V):
-jailshell-2.05b$ python -V
Python 2.3.4
If you have anything prior to 2.3.x you'll have to see about getting your server upgraded. (I'm told the new servers are at 2.3.x while the old are 2.2.x - if you just signed up for a new account, you should be good)
Ok, assuming your on one of the new servers, it's time to get started. Although Django is now offered both as a tarball and from svn, I chose to install from subversion as its easier to update to latest trunk etc. In your shell, make sure you're in your HOME dir and do:
cd ~
svn co http://code.djangoproject.com/svn/django/trunk/ django_src
Run the following commands: (so that Django is available from your shell)
export PATH=$PATH:$HOME/django_src/django/bin
export PYTHONPATH=$PYTHONPATH:$HOME/django_src:$HOME/django_projects
Then add them to your .bash_profile file. Save the file, upload it and then continue with these instructions.
Create a Django projects directory and create your first Django project.
mkdir django_projects
cd django_projects
django-admin.py startproject myproject
If you don't want other users on your shared host to have access to your DB settings, change the permissions on your myproject.settings file so that ONLY YOUR USER can read them.
chmod 600 myproject/settings.py
Edit the myproject.settings (myproject/settings.py) file to add your database connection parameters.
Initialize the database.
Now its time to create the publicly available directory. Whether you set that up as a sub domain through CPanel or just create a sub-dir under ~/public_html (which you can always point to with a sub domain of the same name later) is your choice. For this exersize, we'll assume your just creating a sub-dir, which needs to have the
fcgi.py∞ script.
cd ~/www
mkdir myproject
cd myproject
wget http://svn.saddi.com/py-lib/trunk/fcgi.py
chmod 755 fcgi.py
Now you need to create a file named django.fcgi in the same dir, which should contain the following (replace 'username' with your username on lines 3 and 4 and 'myproject' with the name of your project if it differs from the example used above):
#!/usr/bin/env python
import sys
sys.path += ['/home/username/django_src']
sys.path += ['/home/username/django_projects']
from fcgi import WSGIServer
from django.core.handlers.wsgi import WSGIHandler
import os
os.environ['DJANGO_SETTINGS_MODULE'] = 'myproject.settings'
WSGIServer(WSGIHandler()).run()
Set the correct permissions on django.fcgi. Also, you must ensure django.fcgi uses Unix line endings in order for
FastCGI to work.
At this point you should be able to go to
http://yourdomain.com/myproject/django.fcgi/admin/∞ and
http://yourdomain.com/myproject/django.fcgi/∞. (Note: It usually takes a while for
FastCGI to get ready and actually work. So, just let it sit on your server and keep on trying to access is it--because, for most people, it won't load on the first try.)
If you wish to pass everything in
myproject dir through fast-cgi add the following to your
.htaccess file within ~/www/myproject
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ django.fcgi/myproject/$1 [QSA,L]
If you use the native admin goodness in django, you'll want to create a symbolic link to the admin media files so that your CSS and whatnot works correctly. Here's how:
cd ~/www
ln -s ~/django_src/django/contrib/admin/media media
There are 7 comments on this page. [Display comments]