How To Install Python 2.7 with mod_wsgi on CentOS 5.6 with cPanel

This is a step by step tutorial which will help you install Python 2.7 with mod_wsgi onto CentOS 5.6 and cPanel.


  • CentOS 5.6 32 or 64 bit with root access

  • cPanel

Note: we are not using cPanel custom modules guide because it only works with built-in Python 2.4.

Creating Python folder

mkdir /usr/src/python2.7
cd /usr/src/python2.7

If required by your project, you can install SQLite
tar zxvf sqlite-autoconf-3070701.tar.gz
cd sqlite-autoconf-3070701
make install

Installing Python 2.7 into alternate location since we don’t want to break Centos 5.6 (yum) that uses Python 2.4

cd /usr/src/python2.7/
tar zxvf Python-2.7.2.tgz
cd Python-2.7.2
./configure --prefix=/opt/python2.7 --with-threads --enable-shared
make install

Creating symbolic link to the alternate Python version

ln -s /opt/python2.7/bin/python /usr/bin/python2.7
echo '/opt/python2.7/lib'>> /etc/

Let’s test if new Python version works


If successful you will see something like this:

Python 2.7.2 (default, Sep  3 2011, 18:28:42)[GCC 4.1.2 20080704 (Red Hat 4.1.2-50)] on linux2

press control+D to exit

Now we need to install Python setup-tools

cd /usr/src/python2.7/
sh setuptools-0.6c11-py2.7.egg --prefix=/opt/python2.7

Installing virtualenv to our Python 2.7

cd /opt/python2.7/bin/
./easy_install virtualenv

Installing mod_wsgi (this module will work only with python 2.7)

cd /opt/python2.7/lib/python2.7/config/
ln -s ../../
cd /usr/src/python2.7/
tar zxvf mod_wsgi-3.3.tar.gz
cd mod_wsgi-3.3
./configure --with-python=/opt/python2.7/bin/python
make install

We need to avoid cPanel’s easy_apache clearing up /usr/local/apache/modules folder

mkdir /usr/local/apache/extramodules
mv /usr/local/apache/modules/ /usr/local/apache/extramodules/

Include mod_wsgi into Apache configuration

nano /usr/local/apache/conf/includes/pre_virtualhost_global.conf


LoadModule wsgi_module /usr/local/apache/extramodules/
AddHandler wsgi-script .wsgi

Before we restart Apache, lets test if we have the correct configuration

service httpd configtest

You should get this answer:

Syntax OK

Now restart Apache

/scripts/restartsrv httpd

Python 2.7 with mod_wsgi is now installed on your cPanel server.

You can create a test.wsgi file to test Python scripts

def application(environ, start_response):
"""Simplest possible application object"""
output = "Hello World"
status = '200 OK'
response_headers = [('Content-type', 'text/plain'),
('Content-Length', str(len(output)))]
start_response(status, response_headers)
return [output]

Please post your questions and comments below.

5 thoughts on “How To Install Python 2.7 with mod_wsgi on CentOS 5.6 with cPanel”

  1. a good essay editor will transform your essay coming from being an ordinary dissertation online directly into a great refined AND ALSO concise essay. you employ perhaps spent a great considerable amount connected with time frame greater than ones academic assignment. ones and then step will be in order to polish This to perfection. It is possible for you, being a writer, in order to overlook ones errors that you have committed.

  2. Normal vacation goers involve reductions along with low cost organization plane tickets. For the reason that they vacation with a day-to-day time frame. Couple of oxygen plane tickets organizations think about these types of vacation goers while many don’ travel

  3. Website development, the actual most effective developing portion on the list of numerous procedures connected with graphic design, cell phone calls when the actual innovative in addition to marvelous knowledge of a graphic custom, however it will take creative designers faraway from the actual bodily press having which tend to be almost all acquainted. Instead, website design troubles the actual generation connected with attractive in addition to evocative patterns completely in the electronic, digital camera channel.CMS for html sites

Leave a Reply to achma khatun Cancel reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>