Installing Python / Django on Centos 6.3 is Easy!




NOTE: This article was rewritten (for CentOS 6.4). please read the updated post.

What is Python?

Python is a general-purpose, high-level programming language whose design philosophy emphasizes code readability. Its syntax is said to be clear and expressive.” from Wikipedia.



What is Django?

“Django is a high-level Python Web framework that encourages rapid development and clean, pragmatic design.” from

Installing Python


you may need the EPEL repositories for Centos.

[code lang=”bash”]cd /opt/
rpm -Uvh epel-release-6-8.noarch.rpm
rm epel-release-6-8.noarch.rpm -f[/code]


Installation Process

Simple as:

[code lang=”bash”]yum install python

test python by typing: “python” and you should see something similar to:

As for this time being of writing (June 18 2012), the version of python@EPEL is 2.6.6

Django works with any Python version from 2.6.5 to 2.7. It also features experimental support for versions 3.2 and 3.3. All these versions of Python include a lightweight database called SQLite so you won’t need to set up a database just yet unless you need other SQL


Installing SQL

If you need other SQL Server else then SQLite,  you can follow:
MySQL/MongoDB/CouchDB on RHEL/Centos 6.3
If you don’t need SQL and you installed Python 2.5 or later, you can skip this step for now.





Installing Django

[code lang=”bash”]yum install Django


Testing Django

Test Django by typing python on your command and then:
[code lang=”bash”]import django
print django.get_version()

As you can see, the RPM version is version 1.3.1, while the current release version is 1.4.1. while you are not too far behind using EPEL, you won’t get to play with the last options. Internationalization: in template code is not available in 1.3.1 for example but only from Django 1.4



Creating Project

From the command, cd into a directory where you’d like to store your app, then run the following command:

[code lang=”bash”]django-admin startproject mysite
cd mysite



Starting Server

[code lang=”bash”]python runserver


You’ve started the Django development server, a lightweight Web server – easier to startwithout having to deal with configuring a production server — such as Apache — until you’re ready for production.

Browse to with your Web browser. You’ll see a “Welcome to Django” page. It worked!

To change port:

[code lang=”bash”]python runserver 8080


If you need to start the server to answer not only locally, use:

[code lang=”bash”]python runserver



Configure more…

Config Database

Edit mysite/ It’s a normal Python module with module-level variables representing Django settings.

Help here.


Django using Apache

To run your Django application inside apache – use either mod_python or mod_wsgi, Support for mod_python will be deprecated in a future release of Django. If you are configuring a new deployment, you are strongly encouraged to consider using mod_wsgi or any of the other supported backends.


Install mod_python

For this to work, you must have apache installed and configured.

[code lang=”bash”]yum install mod_python

python using mod_python

you need to configure you apache/VirtualHost to:

[code parse=”no”]

    AddHandler mod_python .py
    PythonHandler mod_python.publisher | .py
    AddHandler mod_python .psp .psp_
    PythonHandler mod_python.psp | .psp .psp_
    PythonDebug On



Testing mod_python

Create a ‘’ file in your apache server. put inside:
[code lang=”py”]<% req.write(“Hello World!”) %>[/code]

and browse to www.your.server/ and you should see the “Hello World!” there.

Django using mod_python

Edit your httpd.conf file:

[code lang=”apache”]

<Location "/mysite/">
    SetHandler python-program
    PythonHandler django.core.handlers.modpython
    SetEnv DJANGO_SETTINGS_MODULE mysite.settings
    PythonOption django.root /mysite
    PythonDebug On


read more…



Install mod_wsgi

Deploying Django with Apache and mod_wsgi is the recommended way to get Django into production.

[code lang=”bash”]yum install mod_wsgi



to use mod_wsgi, create an apache folder inside your project and create a django.wsgi file:

[code lang=”apache” inline=”yes”]import os, sys
os.environ[‘DJANGO_SETTINGS_MODULE’] = ‘mysite.settings’

import django.core.handlers.wsgi

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


and configure your apache with:

[code lang=”apache” inline=”yes”]<VirtualHost *:80>

WSGIScriptAlias / /var/www/django/mysite/apache/django.wsgi

# Alias /robots.txt /var/www/django/mysite/static/robots.txt
# Alias /favicon.ico /var/www/django/mysite/static/favicon.ico
Alias /static/admin/ /usr/lib/python2.6/site-packages/django/contrib/admin/media/
Alias /static/ /var/www/django/mysite/static/
Alias /media/ /var/www/django/mysite/media/

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

<Directory /var/www/django/mysite/media>
Order deny,allow
Allow from all

<Directory /var/www/django/mysite/static>
Order deny,allow
Allow from all



read more on: multiple django sites with apache & mod_wsgi



That’s it!


You’ve Python / Django installed on your Centos 6.3 and a new project template waiting for you to work on.


Continue reading…


4 thoughts on “Installing Python / Django on Centos 6.3 is Easy!

  1. Josh

    Heh, adding EPEL, python 2.5 and Django 1.3.1… You have to be kidding. Do not use CentOS just to use obsolete packages from a third-party repository. This is much simpler to do on Debian or Ubuntu with their supported repositeries or even with a pip, and of course, with the latest python version, with many more efficient ways then mod_python, like guncorn, uwsgi…

    1. admin

      I’ve updated the tutorial (link to the new tutorial at top of this tutorial) to use easy_install command instead for newer version of Django. There are many tutorials how to update Python version if needed. you can use gunicorn / uwsgi also on CentOS.
      Ubuntu is great OS too, but I prefer yum over apt-get anytime. For production server I’d never use ubuntu. It’s easly broken when updated.

  2. predicament

    My spouse and I absolutely love your blog and find nearly all of your post’s to be exactly what I’m looking for. Do you offer guest writers to write content in your case? I wouldn’t mind composing a post or elaborating on some of the subjects you write regarding here. Again, awesome blog!


Leave a Reply

Your email address will not be published.


This site uses Akismet to reduce spam. Learn how your comment data is processed.