How to run Django apps on a CentOS Plesk server

The reason for this tutorial is quite easy: To make this happen, I had to read about 100 pages, all with different solutions, all of them not or only partially working.

After aprox. 8 hours of trial and error, I finally had the best of all the posts compiled to a working set of instructions – so here is the HowTo:

Login as user root to the server in question.

First of all: The usage with the pre-installed mod_python is no fun at all and leads to many errors, therefore it is better to switch to mod_wsgi. If you need the mod_python, stop NOW and search for a different solution. Honestly: I tried it also with mod_python and wasted 6 of the above 8 hours, banging with my head into wall after wall.

Update: And now, that everything was compiled and done, they tell me to use Python 2.6 instead of 2.4 – so please find below the latest install guide for Python 2.6!

Update: Because some years are gone, I’ve updated this article to current versions: CentOS 5.9 – Python 2.7.2 – Plesk 11 (yeah, the Plesk version doesn’t make a difference, I know):

1. Add the EPEL repository for the correct CentOS version your server runs on:

CentOS 5:

2. disable this repository (no joke), otherwise it tries always to update stuff and will break Plesk!
Edit the file /etc/yum.repos.d/epel.repo and set everywhere „enabled=0“

3. install the following packages:

yum install gcc httpd-devel rpm-build python-devel yum-utils
yum install rpmdevtools tk-devel tcl-devel expat-devel db4-devel gdbm-devel sqlite-devel 
yum install bzip2-devel openssl-devel ncurses-devel readline-devel 
yum install git --enablerepo=epel

3b. As there are no (good) Python 2.7 RPMs, we will build them ourselves:

cd /usr/src/redhat
wget -O ./SPECS/python27-2.7.2.spec
wget -O ./SOURCES/Python-2.7.2.tar.bz2
sed -i 's/^%define config_sharedlib no/%define config_sharedlib yes/' ./SPECS/python27-2.7.2.spec
QA_RPATHS=$[ 0x0001|0x0010 ] rpmbuild -bb ./SPECS/python27-2.7.2.spec
yum localinstall --nogpgcheck /usr/src/redhat/RPMS/`uname -m`/python27-*

4. Now we create the pip (Python package installer) tool

cd /usr/src
curl -O
curl -O
yumdownloader --source mod_wsgi --enablerepo=epel
rpm -ivh mod_wsgi*rpm

5. Enable Python 2.7 support for mod_wsgi

sed -i 's,^%configure --enable-shared.*,%configure --enable-shared --with-python=/usr/bin/python2.7,' redhat/SPECS/mod_wsgi.spec

6. Compile mod_wsgi and install

rpmbuild -ba redhat/SPECS/mod_wsgi.spec
rpm -Uvh /usr/src/redhat/RPMS/`uname -m`/mod_wsgi-*.rpm

7. Disable mod_python in Apache
Edit /etc/httpd/conf.d/python.conf


LoadModule python_module modules/

# Override type-map handler for /var/www/manual
<Directory "/var/www/manual/mod/mod_python">
        <Files *.html>
                SetHandler default-handler


#LoadModule python_module modules/

# Override type-map handler for /var/www/manual
#<Directory "/var/www/manual/mod/mod_python">
#        <Files *.html>
#                SetHandler default-handler
#        </Files>

8. Enable mod_wsgi
Edit /etc/httpd/conf.d/wsgi.conf


#LoadModule wsgi_module modules/


LoadModule wsgi_module modules/


Now we’re ready to rumble.

The following describes the setup of the Django Fiber example project (ridethepony) to the domain „“:

1. lets go to the subdirectory in question:

cd /var/www/vhosts/

2. setup a vhost.conf file to redirect dynamic requests to mod_wsgi and static page requests to the common httpdocs directory
Edit conf/vhost.conf, adding the following lines:

Alias /robots.txt /var/www/vhosts/
Alias /favicon.ico /var/www/vhosts/

Alias /static/ /var/www/vhosts/
Alias /media/ /var/www/vhosts/

WSGIScriptAlias / /var/www/vhosts/

<Directory /var/www/vhosts/>
    Order allow,deny
    Allow from all

3. download the application, unpack and rename

git clone git://
mv django-fiber-example pony

4. prepare the application

chmod 0777 pony
cd pony
pip install -r requirements.txt

5. Edit


'NAME': 'fiber_example',                # Or path to database file if using sqlite3.


'NAME': '/var/www/vhosts/',                # Or path to database file if using sqlite3.

6. Edit


# Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.


# Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.

7. Create the default database and import the content

python2.7 syncdb
python2.7 loaddata ./fixtures/example_initial_data.json
chmod 0666 fiber_example

8. copy the static css files into the static directories

python2.7 collectstatic --link
cp -a pages/static/* ../httpdocs/.

9. create the base WSGI file

cd ..

create file django.wsgi with the following content:

import os
import sys

path = '/var/www/vhosts/'
if path not in sys.path:

os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'

import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()

10. activate the Apache and vhost changes:

/usr/local/psa/admin/sbin/httpdmng --reconfigure-all
service httpd restart

11. Enjoy the result at

Das könnte dich auch interessieren …

9 Antworten

  1. Felix Schwarz sagt:

    Instead of rebuilding mod_wsgi it’s easier just to get python26-mod_wsgi from EPEL. Also using python26-virtualenv you can get a local pip instance.

  2. CoKo sagt:

    Was also my first idea – but that was not working on the Plesk server I tested it on – and the co-op with Plesk was a major need…

  3. Marc sagt:

    Wow, so great to see other people having the exact same problem as I do. Not only just the same, but the same setup and need. Great!

    Now only thing is that your article is a bit out of time with the current RPM builds as well as Python is in 2.7 and Django itself is also in a later version.

    If you read this, can you suggest an updated approach to things? I am pretty much sitting on a CentOs5, with Plesk and need to get Django running. Right now mod_wsgi is stopping me from moving ahead, and the dual Python versions installed only makes it all much worse.

    • CoKo sagt:

      Hmm, I haven’t tried it with never versions since then…

      The dual python versions are normally no problem at all, because the newer version is only available if call it including the version number, so all Plesk and other processes keep using the old sluggish 2.4 (which is a MUST if you want to keep compatibility)…

      Tomorrow night I will give it a shot on a clean CentOS 5.8 install with Plesk (still using 9.5.4, though…) and will post an update…

  4. Alf sagt:

    Did you have any luck on the new version?
    I have a similar problem but with CentOS 5.9 (Final)
    Panel version 11.0.9 Update #41, last updated at Mar 16, 2013 01:19 AM

    Trying to get python 2.7 and django 1.5 working on the above setup.

  5. Jose Luis sagt:

    if i install this module of phyton, i lose php compatibility? thx

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert.

I accept that my given data and my IP address is sent to a server in the USA only for the purpose of spam prevention through the Akismet program.More information on Akismet and GDPR.