How to install Django-CMS on CentOS 5.4 with Python 2.6

The other day I was playing around with Django CMS and battling to get it installed on CentOS 5.4. I thought I'd put these notes together in the hope that someone might find them useful. NB. These instructions are not 100% polished, but should be sufficient to get you up and running.

This will install Django 1.1.1 and Python 2.6 on CentOS 5.4, using Apache and mod_python!

Special thanks to fink from #django-cms on for his patience and advice, and the other bloggers around the globe that have written useful articles.

For those not familiar with Django CMS it was born from Django-page-CMS and is now a full product in it's own right. It utilises the Django Python framework.

These instructions are for installing into a very minimal Centos 5.4 (OpenVZ) VPS.

# from
# Install 3rd party repo for Python 2.6
rpm -Uvh
rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-CHL

# install EPEL repository
rpm -Uvh

yum install python26
yum install httpd mod_python26 mysql-server MySQL-python # Apache and mod_python, MySQL
yum install python26-devel # for building pip

# start Apache / MySQL
service httpd start
service mysqld start

# turn on at boot
chkconfig httpd on
chkconfig mysqld on

# install pip from source, EPEL's pip doesnt work with Chris Lea's version of python-setuptools
yum install python-setuptools # from chl repo, this is the python 2.6 version.
cd /tmp
tar -xzf pip-0.6.3.tar.gz
cd pip-0.6.3
/usr/bin/python2.6 install

# maybe now time to disable chris repo
# ... move on to standard install

At this point we should have a working install of Python 2.6 (installed alongside the default Python 2.4 that ships with CentOS / Red Hat 5). And a working pip.

Lets get on with the Django install...

# Later you'll need to install PIL (Python Imaging Library)
# Unfortunately another source install, for which you'll need gcc to compile
yum -y install gcc

# virtualenv is very handy (so I've been told)
pip install virtualenv 
pip install virtualenvwrapper

# (optional) install Django framework from EPEL / CHL
#yum install -y Django, (if not already installed from EPEL or Chris Lea's repo)

# add a user to own our web content
adduser wwwpub -c 'WWW Content Publisher'
mkdir -p /srv/www/django
chown -R wwwpub:wwwpub /srv/www/django

# create a virtual env to hold our project
su - wwwpub
cd /srv/www/django/
mkdir myproj
virtualenv myproj

# enter the new virtualenv
mkdir ~/.virtualenvs
source /usr/bin/virtualenvwrapper_bashrc
source myproj/bin/activate

# install django-cms using pip into our virtual env (not system wide, because virtualenv is activated)
pip install django # or skip this step if you installed django using EPEL / CHL
pip install django-cms
# install the django-cms deps
pip install south
pip install django-reversion

# compile pil from source (needs gcc, which we installed earlier)
pip install pil

# @ install anything else you need

# create the project (not sure if this is the right place, but seems to work)
cd myproj/bin/
./ startproject myproj

At this point you should have a working, albeit un-configured Django install!

Now to setup mod_python. As per create a file in your virtualenv bin directory (/srv/www/django/myproj/bin/ with the following content:

activate_this = '/srv/www/django/myproj/bin/'
execfile(activate_this, dict(__file__=activate_this))

from django.core.handlers.modpython import handler

Next configured Apache. Create a conf file /etc/httpd/conf.d/mysite.conf:

<VirtualHost *:80>

# Todo: set to static content
#    DocumentRoot /srv/www/


    <Location "/">
        SetHandler python-program
        PythonPath "['/srv/www/django/myproj/bin', '/srv/www/django/myproj/bin/myproj'] + sys.path"
        PythonHandler myvirtualproj
        SetEnv DJANGO_SETTINGS_MODULE settings

    ErrorLog /var/log/httpd/
    CustomLog /var/log/httpd/ combined


Restart apache. That should get you up and running.

apachectl configtest # should be ok
apachectl restart

At this point you're all set and you can point your web browser at the IP / hostname you configured with Apache and you should see the Django default page.

Next you'll need to complete the rest of the Django / Django-CMS configuration as per the instructions on their respective websites. eg At the very least the database settings must be set in /srv/www/django/myproj/bin/myproj/ and the database must be synced with python syncdb.

Good Luck!

Further Reading

You might find some of these links useful:

— Andrew

Next entry

Previous entry

Related entries

Similar entries


  1. Arno Smit
    Arno Smit on 06/30/2010 1:18 a.m.

    Hey there. Quite curious to know whether you got libjpeg and pil to function through just "pip install pil"

  2. Roman Rejmkhe
    Roman Rejmkhe on 07/24/2010 8:57 a.m.

    Seems I crash at the point where we start to use pip:[root@ip site-packages]# pip install virtualenv
    Traceback (most recent call last): File "/usr/bin/pip", line 2, in
    import pip, sys
    File "/usr/lib/python2.6/site-packages/pip/", line 8, in
    from pip.baseparser import parser
    File "/usr/lib/python2.6/site-packages/pip/", line 5, in
    import pkg_resources
    ImportError: No module named pkg_resources
    On I found you workaround for this (, but it didn't work for me:[root@ip pip-0.6.3]# cd /usr/lib/python2.4/site-packages/
    [root@ip site-packages]# ln -s /usr/lib/python2.6/site-packages/pkg_resources*
    [root@ip site-packages]# ln -s /usr/lib/python2.6/site-packages/pkg_resources.pyo
    [root@ip site-packages]# ln -s /usr/lib/python2.6/site-packages/pkg_resources.pyc
    [root@ip site-packages]# ln -s /usr/lib/python2.6/site-packages/
    [root@ip site-packages]# pip install virtualenv
    Traceback (most recent call last): File "/usr/bin/pip", line 2, in
    import pip, sys
    File "/usr/lib/python2.6/site-packages/pip/", line 8, in
    from pip.baseparser import parser
    File "/usr/lib/python2.6/site-packages/pip/", line 5, in
    import pkg_resources
    ImportError: No module named pkg_resources
    Can you help me somehow with this?

  3. Roman Rejmkhe
    Roman Rejmkhe on 07/24/2010 9:17 a.m.

    Looks like I accidently found a workaround for my case:
    tar -xzvf flup-1.0.2.tar.gz
    python flup-1.0.2/ install
    During install, it says something about wrong setuptools and asks if I want to download and install it. After saying yes and finishing installing of flup, the pip started to work.

  4. Simon Morris
    Simon Morris on 09/30/2010 3:31 a.m.

    This really helped me get this working, thanks

  5. emetib
    emetib on 03/11/2011 10:52 p.m.

    pip install virtualenv
    bash: pip: command not found
    pip –version
    pip: command not found

    How do I uninstall pip 0.6.3
    so I can install pip 0.8.2?


Pingbacks are open.

Post your comment

Site theme originally by