Jul 16, 2009
Installing mod_python
I want to share to you how I was able to add python support on to my fedora server.
First, you must check your server if you have already Python installed by simply typing python on the command line.
then, download mod_python from their site. After downloading, decompress the file, and configure the decompressed file with apxs or apxs2. apxs/apxs2 is necessary for compilation of DSO libraries in Apache. You may follow the step-by-step instruction in their documentation.
Finally, do a make install_dso to install mod_python to apache.
To test if you have successfully done the installation of mod_python to server,
Configure httpd.conf by adding these lines,
{code}
<Directory “/path/to/python/testfile”>
AddHandler mod_python .py
PythonHandler mptest
PythonDebug On
</Directory>
{/code}
create a file with the name you specified in PythonHandler, and that is mptest.
The code in the mptest.py should look like this:
(I appreciate Graham’s correction on the sample code where you don’t have to include the #! because you are not trying to run the script as a CGI script)
{code}
#!/usr/bin/env python
from mod_python import apache
def index(req):
req.content_type = ‘text/plain’
req.write(“Hello World!”)
apache.OK
{/code}
Take note of proper indentation of every line of code in python. It is very important!


You do not the need the #! line, it is not a CGI script.
@Graham,
yes, you’re right. thank you.
[...] blog post Previously I made a blog post regarding installing mod_python. Now I will share with you how to query mysql tables with Python and [...]