Mod_python on OpenSUSE 11.0

Mod_python is an Apache module that embeds the Python interpreter within the server. Here is step by step what I did to configure it for OpenSUSE 11.0:

1. Install mod_python:

1
$ sudo zypper in apache2-mod_python

2. Enable mod_python: edit /etc/sysconfig/apache2 and add python to the APACHE_MODULES line, so your line will look like:

1
APACHE_MODULES="actions alias auth_basic authn_file authz_host authz_groupfile authz_default authz_user authn_dbm autoindex cgi dir env expires include log_config mime negotiation setenvif ssl suexec userdir php5 python"

3. Run SuSEconfig

4. Configure Apache to handle Python files:

1
$ sudo vim /etc/apache2/conf.d/python.conf  # create python.conf file

5. Add the next lines to your python.conf file:

1
2
3
4
5
6
7
8
9
<Directory /srv/www/htdocs/>
  Options Indexes FollowSymLinks MultiViews
  AllowOverride None
  Order allow,deny
  allow from all
  AddHandler mod_python .py
  PythonHandler mod_python.publisher
  PythonDebug On
</Directory>

6. Restart apache server:

1
$ sudo /usr/sbin/rcapache2 restart

7. Create a simple .py file, put it in /srv/www/htdocs/ and test to see if it is working with http://localhost/filename.py:

1
2
def index(req):
  return "It Works: mod_python ENABLED";

The other method is to configure the PSP Handler. PSP means Python Server Pages. PSP files have the extension .psp. If you follow this method it will allow you to include Python code directly in HTML code. To do that, I am sure that google can help you, for me the first method is enough.

That’s all. The above procedure will work also for CentOS, replacing the corresponding commands and the place where the files are.

If you enjoyed this post, please consider to leave a comment or subscribe to the feed and get future articles delivered to your feed reader.

Comments

gr8 work man you save my day thanx a lot :)

I used to use that config once in my laptop and that worked fine. I do some ‘print’ and it works well. But i recently installed modpython on a desktop (with suse 11.1), did the same way and the same prints doesn’t work. It just give me a “http 404 not found” message every time. Do you know what could be my mess? Perhaps I forget to install any package?

Followed all the steps on my suse11. not working plz help. I still get an option to save the test.py file. it does not get executed.

Leave a comment

(required)

(required)