How to setup Django on Slicehost

So you’re setting a new host. This should make it easier to setup on CentOS 5.5. This list isn’t complete since you will need to setup django but this should at least get the system the basic packages to start moving.

  • vim-enhanced
  • python mod_python
  • httpd
  • mysql.x86_64
  • mysql-server.x86_64
  • subversion.x86_64
  • python
  • screen
  • mlocate
  • python-devel.x86_64
  • mysql-devel.x86_64
  • gcc
  • python-setuptools.noarch

Download  Open Source packages

Django

wget http://www.djangoproject.com/download/1.2/tarball/
tar -zxvf django.1.2.tar.gz
cd Django.xxx
python setup.py install

Once installed, this should make django-admin.py available from command line. Installation of django typically goes into /usr/lib/python2.x/site-packages/django

MySQL EGGs

You will need to have the mysql-python connector to allow django/python to connect properly to the database. This of course will require MySQL server and client is installed and running on the box.

wget http://sourceforge.net/projects/mysql-python/files/mysql-python-test/1.2.3c1/MySQL-python-1.2.3c1.tar.gz/download
tar -xvzf MySQL-python-1.2.3c1.tar.gz
python setup.py build
python setup.py install

Apache Configurations

There are several small steps that need to be happen before django will work properly.

Django admin files have to be made available to the public.

ln -s /var/www/html/media  /usr/lib/python2.4/site-packages/django/contrib/admin/media

Setup an eggs directory for apache

mkdir /var/www/eggs

Add the following to the httpd.conf file

<Location “/”>
SetHandler python-program
PythonPath “[‘/usr/local’, ‘/var/www’] + sys.path”
PythonHandler django.core.handlers.modpython
SetEnv DJANGO_SETTINGS_MODULE apps.settings
SetEnv PYTHON_EGG_CACHE /var/www/eggs
PythonDebug On
ErrorDocument 404 /errors/404.html
</Location>

<Location “/media”>
SetHandler None
</Location>

At this point, you have about 80% of the work done to get django up and running from a blank host. All that needs to happen from here is to configure your settings.py and create your django application. Good luck and hope this helps!