Django with fastcgi

While it is possible to install Django on HostGator servers, it is not a supported application, and we are unable to install it for you. It is recommended that you have a developer available to assist you with any issues that may arise while installing or using this software.

Dedicated and VPS Prerequisites

You will need the FLUP module to install Django. Shared and Reseller plans already have the module installed. However, VPS and Dedicated customers will need to install this module prior to installing Django. You can install FLUP by running the following shell command:

easy_install flup

Installing Django

If you are installing on a dedicated server or VPS you can install Django by running the following shell command:

easy_install django

For Shared or Reseller accounts, you will need to perform a manual installation:

  1. Download the latest release from the Django official download page.

  2. Untar the downloaded file. This will create a new directory.

  3. Change into the directory created in the previous step.

  4. Run the following shell command to complete the installation of Django.

python install

Setting up Django Projects

In order to create a new Django project, simply run these commands replacing newproject with the name of the directory you wish the project to be run from and replacing username with your cPanel username: startproject home/username/public_html/newproject
cd newproject
chmod +x
./ startapp newapp

Managing your Project

In order to manage your project, you will need to set up an index file that you can access from your browser.

  1. Create index.fcgi and place it inside your public_html directory, or the document root you desire.
  2. Change the file's permissions to 0755.
  3. Edit the file and enter this code:
import sys, os, user

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

# Switch to the directory of your project.

# 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")
Note: The above code is only an example, and you will need to modify the path names specified to match your configuration. (For example, change "username" to your cPanel username, etc.)
  1. Add the following .htaccess rewrite rules to the .htaccess file 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]

Multiple Python Installations

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. To resolve the issue, simply run the following from the command line:

/usr/bin/easy_install django flup==1.0.2