Apache HTTP Server/mod python

From ArchWiki
< Apache HTTP Server
Revision as of 05:45, 3 January 2011 by Louipc (talk | contribs) (Install Package)
Jump to: navigation, search

This template has only maintenance purposes. For linking to local translations please use interlanguage links, see Help:i18n#Interlanguage links.

Local languages: Català – Dansk – English – Español – Esperanto – Hrvatski – Indonesia – Italiano – Lietuviškai – Magyar – Nederlands – Norsk Bokmål – Polski – Português – Slovenský – Česky – Ελληνικά – Български – Русский – Српски – Українська – עברית – العربية – ไทย – 日本語 – 正體中文 – 简体中文 – 한국어

External languages (all articles in these languages should be moved to the external wiki): Deutsch – Français – Română – Suomi – Svenska – Tiếng Việt – Türkçe – فارسی


Mod_python is an Apache module that embeds the Python interpreter within the server. With mod_python you can write web-based applications in Python that will run many times faster than traditional CGI and will have access to advanced features such as ability to retain database connections and other data between hits and access to Apache internals. A more detailed description of what mod_python can do is available in this O'Reilly article.


Apache Module : Mod_Python

This document describes how to set up and test the Apache module Mod_Python on an Arch Linux system.

Install Package

Find the Template:Package AUR package in the AUR.

Configure Apache

  • Add this line to /etc/httpd/conf/httpd.conf:
LoadModule python_module modules/mod_python.so
  • Restart Apache
# httpd -k restart
  • Check to make sure that Apache loaded correctly

Test Mod_Python

  • Add this block to /etc/httpd/conf/httpd.conf:
<Directory /home/www/html> 
   AddHandler mod_python .py
   PythonHandler mod_python.publisher 
   PythonDebug On 
  • Create a file in /home/www/html/ called mptest.py and add this as contents:
from mod_python import apache
def handler(req):
    req.content_type = 'text/plain'
    req.write("Hello World!")
    return apache.OK
  • Restart Apache
# sudo apachectl restart
  • Check to make sure that Apache loaded correctly
Hello World!

With the configuration written above, you can also point your browser to any URL ending in .py in the test directory. You can for example point your browser to /foobar.py and it will be handled by mptest.py.

See Also