I haven't fully tested this yet, so I may have forgotten a step (or two) but this should be fairly accurate.
-
Set up SSH access on the host.
-
Add your SSH to ~/.ssh/authorized_keys on the host.
-
SSH in to the server.
-
Set up Git.
wget http://kernel.org/pub/software/scm/git/git-1.7.0.6.tar.gz tar xvf git-1.7.0.6.tar.gz cd git-1.7.0.6 ./configure --prefix=$HOME make install
-
Test the Git installation.
cd ~ git
-
Download Setuptools for Python 2.6.
wget http://pypi.python.org/packages/source/s/setuptools/setuptools-0.6c11.tar.gz#md5=7df2a529a074f613b509fb44feefe74e tar xvf setuptools-0.6c11.tar.gz cd setuptools-0.6c11
-
Create a local site-packages directory.
mkdir ~/lib/python2.6 ~/lib/python2.6/site-packages
-
Update your PYTHONPATH. Use a text editor to add this line to your ~/.bash_profile:
export PYTHONPATH="${HOME}/lib/python2.6/site-packages/:${PYTHONPATH}"
-
Install Setuptools.
python2.6 setup.py install --prefix=$HOME
-
Install pip.
easy_install-2.6 --prefix=$HOME pip
-
TODO: Virtualenv support? (HostMonster does not have python-devel, so you get this error when trying to create a new virtual environment because the setuptools bootstrap fails:
error: invalid Python installation: unable to open /usr/lib/python2.6/config/Makefile (No such file or directory)
) -
Set up a SSH keypair for the hosting account.
cd ~/.ssh ssh-keygen (name it id_rsa)
-
Copy and paste the generated public key as a deploy key to your GitHub repository administration page.
cat id_rsa.pub
-
Create a directory for your django sites and clone your repository.
mkdir ~/django-sites cd ~/django-sites git clone git://<repository url> cd <repository directory>
-
Install dependencies from your pip requirements file. (You are using requirements files, right?) You'll want to include Django, PIL, database drivers, etc. in here.
pip install -r requirements.txt --install-option="--prefix=${HOME}"
-
Sync your database, and load any test data that you have. This may vary, depending on your setup, but I'm assuming your manage.py (or similar) is located in the project root.
./manage.py syncdb
-
Change directories to the web root, and set up your fcgi file for the site. Name it something like
<project name>.fcgi
.#!/usr/bin/python2.6 import sys, os HOME = '/home/<hostmonster username>/' SITE_PACKAGES_DIR = HOME + 'lib/python2.6/site-packages/' sys.path.insert(0, SITE_PACKAGES_DIR[:-1]) # Add any other references to eggs that are not autoloaded for some reason(?) here: # For example, sys.path.insert(0, SITE_PACKAGES_DIR + 'flup-1.0.2-py2.6.egg') sys.path.insert(0, HOME + 'django-sites') os.chdir(HOME + 'django-sites/<project directory name>') # Set the DJANGO_SETTINGS_MODULE environment variable. os.environ['DJANGO_SETTINGS_MODULE'] = "<settings file here>" # This will probably be something like "myproject.settings" if you're running a simple project. from django.core.servers.fastcgi import runfastcgi runfastcgi(method="threaded", daemonize="false")
-
Make sure you have flup installed! You can install it with
pip install flup==1.0.2
. Make sure to add it to yourrequirements.txt
!) -
Set up your .htacccess file, with the following contents:
AddHandler fastcgi-script .fcgi AddHandler fcgid-script .fcgi RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ <project name>.fcgi/$1 [QSA,L]
-
If you are serving static media out of the same subdomain, symbolically link your static or media directory into the web root. You'll also have to do this for any admin media (the path to admin media will be
$HOME/lib/python2.6/site-packages/django/contrib/admin/media
.)ln -s $HOME/django-sites/<repository directory>/rest/of/path/to/static/media static
-
Make sure your .fcgi file is running properly. It's just a normal Python script, so you should be able to execute it as such. (Although you might need to "chmod +x" it first.)
./<project name>.fcgi
You should get some errors at the top of STDERR, but that's OK — they'll probably look like this…
WSGIServer: missing FastCGI param REQUEST_METHOD required by WSGI! WSGIServer: missing FastCGI param SERVER_NAME required by WSGI! WSGIServer: missing FastCGI param SERVER_PORT required by WSGI! WSGIServer: missing FastCGI param SERVER_PROTOCOL required by WSGI!
-
Profit!