Monday, August 07, 2006

mod_python on Apache

Python .... hmmm, it's sound like a snake. But what i meant is a programming language. After succeed installing mod_python, i'm trying to add this line below in to the Apache httpd.conf :

LoadModule python_module libexec/
AddHandler python-program .py

Then i'm restarting the Apache web server. After that, i create a file named "" under "pypublish" directory, and the code look like below :

def index():
return "This is only a test."
def peyton():
return "Peyton wrote this."

The problem is, why when i'm calling http://python.intranet/pypublish/ in the browser, the code above shown again. It's like that file not known as a python file or look like no handler for that file?

To solve the problem, in the httpd.conf configuration i'm adding the line like this below :

# To load python module:
LoadModule python_module libexec/

# Python Project
DocumentRoot /data/data/project/learn/python/
ServerName python.intranet
<Directory /data/data/project/learn/python/pypublish>
AddHandler python-program .py
PythonHandler mptest
PythonDebug On

Sorry, i create a new file named "" with the content :

from mod_python import apache

def handler(req):
req.write("Hello Toserba Yogya IT&S Developer, welcome to the Python World!")
return apache.OK

And then when it running to the browser with http://python.intranet/pypublish/ the program running well.

1 comment:

harikrishna said...

iam using fc5 in system
plz tell me how to install mod_pythonand how to run it in my localhost?
i also created public_htmland inthat cgi-bin(dir) but i dont know where to write .htaccess and wat to write in it?