Install Django on Arvixe

Recently I had to spend a few good hours trying to figure out how to install Django on a shared host at Arvixe. I thought I’d document it for others and for my future reference, as I’m sure I’ll forget all this and don’t want to have to re-discover it.

It’s all done in a shell, so if you don’t have shell, you have to request it.

Step 1: Get python 2.7

mkdir temp
cd temp
wget http://www.python.org/ftp/python/2.7.2/Python-2.7.2.tgz
tar -xzf Python-2.7.2.tgz

Step 2: Compile and install Python

cd Python-2.7.2
./configure
make altinstall prefix=~ exec-prefix=~
cd ~/bin
ln -s python2.7 python

Add an alias to your .bashrc
vi .bashrc
add this line: alias python=’~/bin/python’

Login again, and check by running python -V
You should see: Python 2.7.2

Step 3: Install Django

Get DjangoX.X.tar.gz in temp
tar -xzf DjangoX.X.tar.gz
python setup.py install

At this point you can check it was installed correctly:
python
import django
django.get_version()

Step 4: Install setuptools (dependency of MySQLdb at step 5)

Download setuptools-0.6c11-py2.7.egg from http://pypi.python.org/pypi/setuptools#downloads
Install with:
sh setuptools-0.6c11-py2.7.egg

Step 5: Install MySQLdb (mysql-python)

Download it MySQL-python-1.2.3.tar.gz from http://sourceforge.net/projects/mysql-python/files/mysql-python/1.2.3/
tar -xzf MySQL-python-1.2.3.tar.gz
cd MySQL-python-1.2.3
python setup.py build
python setup.py install

Step 6: Create a MySQL via the arvixe cpanel

This will be something like: _

Change the settings.py in django:
‘ENGINE’: ‘django.db.backends.mysql’
‘NAME’: _ (e.g. ‘mikep_mysqldb’)
‘USER’: your_arvixe_user,
‘PASSWORD’: your_arvixe_password,
‘HOST’: ”,
‘PORT’: ”

Step 7: Setup the cgi script

I’ve used this cgi script: https://code.djangoproject.com/attachment/ticket/2407/django.cgi
Place it in ~/public_html/cgi-bin

cd ~/public_html/cgi-bin
wget https://code.djangoproject.com/raw-attachment/ticket/2407/django.cgi

There are 3 lines you have to change:
1: #!/home//bin/python <- this is the new python you've just installed
95: sys.path.append("/home//djangorepo”)
96: os.environ[‘DJANGO_SETTINGS_MODULE’] = ‘djangoapp.settings’

The above assumes that you have installed your django site in djangorepo and your django app is called djangoapp.
In other words, you have something like this:
/home//djangorepo/djangoapp (in this you have manage.py, settings.py, etc.)

This script needs to be executable! If you don’t have, you’ll get HTTP 500 and you can’t see the Apache error log, so you’ll be stuck.

chmod 755 ~/public_html/cgi-bin/django.cgi

Step 8: Add the .htaccess

Place a file call .htaccess in ~/public_html

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

That’s it! Point your browser to your url and enjoy!

Advertisements

3 Responses to “Install Django on Arvixe”

  1. Alex Ford Says:

    I’m sure this probably is impossible to do with Windows hosting? Python runs on Windows hosting but we don’t appear to have access to tools like the ones you mention here.

  2. Alex Laird Says:

    What do you do in this case to emulate restarting the server, as the Django tutorials discuss doing sometimes after you’ve modified resources?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: