Custom Search

Thursday, October 22, 2009

Installing mod_python

To install mod_python, we simply run:

apt-get install libapache2-mod-python


3 Configuring Apache

Now we must configure Apache so that it can handle Python files. There are two ways of doing so. The first (and default) one is to use the Publisher Handler. It allows you to write pure Python scripts with the extension .py that will be interpreted by Apache. The second way is the PSP Handler. PSP stands for Python Server Pages. It allows you to embed Python code directly in HTML code, similar to PHP. PSP files have the extension .psp.


3.1 The Publisher Handler

To enable the Publisher Handler, we must open our vhost configuration (I'm using the default vhost on Debian with the document root /var/www; the configuration for this vhost is located in /etc/apache2/sites-available/default) and add the lines AddHandler mod_python .py, PythonHandler mod_python.publisher, and PythonDebug On to it:

vi /etc/apache2/sites-available/default

[...]

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

[...]

Restart Apache afterwards:

/etc/init.d/apache2 restart

Now we create a little Python test script (e.g. /var/www/test.py) with pure Python code in it...

vi /var/www/test.py

def index(req):
return "Test successful";

From
http://www.howtoforge.com/embedding-python-in-apache2-with-mod_python-debian-etch

No comments:

Post a Comment