How to install Django on shared cPanel hosting


1. Log into your account using SSH, and run the following

Note: MySQL-python is the mysql module, psycopg2 is the postgresql module. Depending on your needs you may choose to leave these modules out.

$ pip install django==1.8.7
$ pip install flup==1.0.2
cd ~ && virtualenv -p /usr/bin/python2.7 djangoenv
source ~/djangoenv/bin/activate
pip install flup6 paste fastcgi MySQL-python psycopg2

2. Create a .htaccess file in your Django folder which contains:

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

3. Create a file called app.fcgi - replace file paths with the correct locations. Ensure this file has permissions 755:

#!/home/your_username/djangoenv/bin/python2.7
import sys, os

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

# Switch to the directory of your project. (Optional.)
# os.chdir("/home/user/myproject")

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

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