Installing Apache mod_python

Posted under » Ubuntu » Apache » Python on 30 September 2009

Command line version of python is already installed in ubuntu. To get into python's interactive mode, open Terminal and then type 'python'. You will see something like this.

# Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41)

Now lets install apache mod python

$ apt-get update
$ apt-get install libapache2-mod-python libapache2-mod-python-doc

Just like PHP, you have to add the adhandler to the apache config

 <Directory /var/wwwpy>
        AddHandler mod_python .py
        PythonHandler hello
        PythonDebug On

Restart Apache for the new config to work.

Now create a file on to the webserver.

from mod_python import apache
def handler(req):
        req.content_type = 'text/html'
        req.write('Testing mod_python')
        req.write('Hello World!')
        return apache.OK

Now use firefox to go to


You should see "Hello World!" on screen.

Update : You should use mod_wsgi instead.

web security linux ubuntu python django git Raspberry apache mysql php drupal cake javascript css AWS IOT