Installing Python2.6, mod_wsgi, and Python-MySQL on a CentOS box
Posted by adminOct 31
UPDATED: January 31st, 2011: Python 2.6 now is in the normal EPEL repositories. There are some changes in the explanations below
I’ve always hated Centos, probably because I’ve never been in a situation where I had to deal with the network security (other than the obvious stuff to ward off cross-site-scripting attacks and the such). Of course, that being the case, I did wind up dealing with CentOS at work and I had to get Django, Python 2.6 and the such functional.
Centos throws a few curveballs your way.. YUM is built on Python 2.4, and upgrading to a newer version supposedly breaks the program. Going back to Python 2.4 was not an option, mainly because all my python experience is on Python 2.5 / 2.6, and I don’t want to go back and learn an older non-maintained version of the language for a server. On the other hand, I didn’t want to lobby to just install Ubuntu.
This assumes you already have a normal LAMP setup. Furthermore, I’m assuming you do not have mod_python installed. This threw me for a loop for the longest time, so take this for what its worth.
The VERY FIRST STEP (if you are running a clean install of CentOS) is to get the dev tools installed.
# sudo yum groupinstall 'Development Tools'
After that, install Python 2.6 (or anything else newer in the 2.x series). As of January 31st, these are in the EPEL repositories; if you don’t have the EPEL repositories enabled, do the following:
# rpm -Uvh http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-3.noarch.rpm
# yum repolist
Once that’s done, run yum update to get everything setup, and then install Python & the MySQL dependencies (if they aren’t already installed)
# yum install python26* mysql-devel mysql-server
This installs pretty much everything Python- & MySQL-related that you need. You will need to run the following to get an extra piece of information:
Python 2.6.5 (r265:79063, Apr 16 2010, 13:09:56)
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.prefix
'/usr'
The prefix (/usr) is important for later. Set it aside and finish up.
# cd ~
# wget http://sourceforge.net/projects/mysql-python/files/mysql-python/1.2.3/MySQL-python-1.2.3.tar.gz/download
# sudo tar xzvf MySQL-python-1.2.3.tar.gz
# cd MySQL-python-1.2.3*
# python26 setup.py install
(Don’t forget to create a user for use by Django in the database)
# cd ~
# wget http://modwsgi.googlecode.com/files/mod_wsgi-3.3.tar.gz
# sudo tar xzvf mod_wsgi-3.3.tar.gz
# cd mod_wsgi-3.3*
# ./configure --with-python=/usr/bin/python2.6
# make
# make install
Now you need to fix up your Apache configuration. I won’t pretend to be an expert with WSGI (although I’ve managed to get it running on 3 different OSes running Apache), but make sure you include the following, somewhere near the Module block in the httpd.conf file.
WSGIPythonHome /usr/
As long as you have this setup, and a proper WSGI script, you should be able to get up and running.
The Django installation is quite easy. Go into the Django source directory and type in
# python2.6 setup.py install
That will take care of making sure Python2.6 also has access to django.
If you don’t want to install using the source code, you can also do this through pip. Follow the instructions here to install pip (while updating the version of pip to 0.8.2) and then type in
# pip install django
That’s pretty much it. I’m sure there is something unclear, but I’ve got to get back to work -_-
No comments
You must be logged in to post a comment.