Configure Python / Django to use mod_wsgi (MySql) on Linux
Having Python 2.6 pre-installed with my version of Ubuntu (9.10 – Karmic Koala), the first thing we need to do in order to install MySql with Python & Django is to check for the latest available version of the mod-wsgi module on google code, http://code.google.com/p/modwsgi/downloads/list. Modify your commands in the following steps to suit the exact mod_wsgi file version you will use. In my case, version 3.1 was the most recent so I followed these steps:
Part 1
- mkdir ~/dload && cd ~/dload
- wget http://modwsgi.googlecode.com/files/mod_wsgi-3.1.tar.gz
- tar zxvf mod_wsgi-3.1.tar.gz && cd mod_wsgi-3.1
- Now that the mod_wsgi module is installed on our system, we must create a load file for it with the following command: sudo echo “LoadModule wsgi_module /usr/lib/apache2/modules/mod_wsgi.so” | sudo tee /etc/apache2/mods-available/wsgi.load . We use the sudo tee command for the second part of the operation to carry through the privelages, otherwise you will receive an error.
- *Now we must instruct Apache to load the mod_wsgi module with the following command: sudo a2enmod
- At the prompt, enter wsgi
- Our only remaining task is to restart Apache server with the following command: sudo /etc/init.d/apache2 restart
* Part 2
I experienced an error at step 5, something to the effect that I required python-setuptools to be installed, which is a distribution to facilitate easier build and distribution of Python packages, especially those with dependencies. Follow these steps to install python-setuptools:
- Download the appropriate .egg file for your version of Python, in my case, it is version 2.6 so I downloaded the file: setuptools-0.6c11-py2.6.egg from http://pypi.python.org/pypi/setuptools#files
- Run it as if it were a shell script, e.g: sh setuptools-0.6c11-py2.6.egg
Setuptools will install itself using the matching version of Python (e.g. python2.6), and will place the easy_install executable in the default location for installing Python scripts (as determined by the standard distutils configuration files, or by the Python installation).
You can now return to step 5 of Part 1 and continue through to the finality of installing the load file and then restarting the Apache server at step 7.

