How to install Python with mod_wsgi on a CentOS 5 or 6 VPS or Server with cPanel Print this Article
How To Install Python 2.7 with mod_wsgi on CentOS 5 or 6 with cPanel
The world knows that cPanel/WHM is not too Django, or python friendly. However, this is a step by step tutorial which will help you install Python 2.7 with mod_wsgi onto CentOS 5 or 6 and cPanel so that you can begin Python development on a cPanel/WHM VPS or server. All of our Shared and Reseller plans come with a Django/Python friendly hosting environment.
This tutorial has been updated on 8/19/13.
CentOS 5/6 32 or 64 bit with root access
Note: We are not using cPanel custom modules guide because it only works with built-in Python 2.6.
Creating Python folder
If required by your project, you can install SQLite by using WHM's built in 'Easy Apache' script and selecting 'MySQLI' on the 'exhaustive list' or options.
Installing Python 2.7 into alternate location since we don't want to break Centos 5/6 (yum) that uses Python 2.4
tar zxvf Python-2.7.5.tgz
./configure --prefix=/opt/python2.7 --with-threads --enable-shared
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/ld.so.conf.d/opt-python2.7.conf
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
sh setuptools-0.6c11-py2.7.egg --prefix=/opt/python2.7
Installing virtualenv to our Python 2.7
Installing mod_wsgi (this module will work only with python 2.7)
ln -s ../../libpython2.7.so
tar zxvf mod_wsgi-3.3.tar.gz
We need to avoid cPanel's easy_apache clearing up /usr/local/apache/modules folder
mv /usr/local/apache/modules/mod_wsgi.so /usr/local/apache/extramodules/
Include mod_wsgi into Apache configuration
LoadModule wsgi_module /usr/local/apache/extramodules/mod_wsgi.so
AddHandler wsgi-script .wsgi
Before we restart Apache, lets test if we have the correct configuration
service httpd configtest
You should get this answer:
Now restart Apache
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'),
Was this answer helpful?
Here at Webhostpython.com, we completely support Python and the Django framework. This has been...
Python is by far one of the most beautiful programming languages in the world. Webhostpython.com...
Django is a free and open source web application framework, written in Python, which follows the...
Python is a beautiful programing language, one that we strongly support here at...
Powered by WHMCompleteSolution