Sunday, July 05, 2009

Debian Apache AddHandler mod_python

When you like to create a web-application using python and you are running a Apache webserver you will most likely like to add the handler mod_python. mod_python will allow you to run for example python with a extension like .py and .psp .

The below example is done on a clean default install of a Debian linux server. First thing to do is install the mod_python module in apache. You can do so by executing the following apt-get command.

apt-get install libapache2-mod-python

Now we have mod_python installed however we have to do some manual configuration. open the following file in vi (or any editor you like) /etc/apache2/sites-available/default . Here you have to look for the vhost configuration part you like to add the handler to. As this is a default install you will be looking for the /var/www location.

Here you will have to add the following lines:
AddHandler mod_python .py .psp
PythonHandler mod_python.publisher | .py
PythonHandler mod_python.psp | .psp
PythonDebug On

This will make sure that you have something like this for you vhost configuration:

Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
AddHandler mod_python .py .psp
PythonHandler mod_python.publisher | .py
PythonHandler mod_python.psp | .psp
PythonDebug On


Now you can test it by adding some .py and .psp code to /var/www and call it with a browser. If all is correct you should see the result of your code and not the code itself.


No comments: