Friday, February 26, 2010

It's a unix system: Part 2 - Installing Django 1.1.1, Python 2.6.4 and MySQL 5.1.44

So this week I have mostly been configuring our VPS box. Although you'd think this would be an easy job, nothing in the IT world is ever easy.

Firstly getting back to grips with Unix took some time, getting used to the VI editor, chmod/chowd-ing, running shell and pearl scripts was a bit like attempting to remember leaving cert Irish. Unintuitive and slow.

So first I decided to put some server software onto the site. Cpanel cost 120 euro per year to install, a shit load of cash that didn't really need to be spent so I decided to battle with Webmin. Webmin uses port 10000 on the VPS and installed clean first time (from rpm). Trying to login though I kept getting 404s. I contacted the server admin and he said he can connect fine from his end. Queue a day or two of opening ports on routers, netstat-ing, opening ports on the firewall. I then tried to run Webmin through Apache, ambitious it turned out because Webmin was having none of it, the username/passwords weren't liked by the server and more time wasted. Eventually I sent an email of desperation to the server admin who discovered there was a firewall blocking the port his end. Nice. Once this was opened webmin was usable.

Now to the actual project part. I went with mod_wsgi to install Python as this is the faster and recommended plugin to get apache working with djgano/python. This installed fine, updated the httpd.conf to include the .so file. Few tweaks here and there. Python also installed clean as did Django.

Now to MySQLdb. This is a python MySQL plugin and causes problems everytime I try to install it. So I discovered a nicer way of doing it.

The first problem you encounter is setuptools missing. You could install setuptools into your python but I found it easier to edit the setup.py and enter

import distutils
from distutils.core import setup, Extension

This will add the libraries you need (this is for python 2.6 btw). You'll have to remove the setuptools reference.

Next the install will throw an error saying something about mysql_devel or mysql_config. This basically means you don't have the full MySQL install on your system. I made the mistake of just adding the client like you do for windows. Normally with MySQL I click the first download link and run the package but not so for unix.
It involves downloading the client, the server and the development package and running the rpms (rpm -i ) . Look down the download page and you'll see all the installations.

Once these are in rerun the install of MySQLdb and it'll work as it should.

Next is the problem of Apache and wsgi. The Django website will work fine for the scaffold code that goes around a wsgi installation. The biggest problem I had was with 403 errors appearing for all aliases and directories. Everything I tried didn't work and I've been to alot of sites on this. By some strange chance I got this to work and open my directories:
  
    Options Indexes MultiViews
    AllowOverride None
    Order allow,deny

This should get you up and running with Apache 2.2, Django 1.1.1, Python 2.6.4 and MySQL 5.1.44. My install was on a Linux RedHat CentOS server.

No comments:

Post a Comment