Installing mod_python apache on windows

October 17th, 2008

To install and test mod_python Apache on Windows (assuming that you’ve already had Apache and Python installed):

  1. Download mod_python Win32 Binaries from http://httpd.apache.org/modules/python-download.cgi
  2. Run the installer. When prompted for Apache installation directory, type C:\Program Files\Apache Software Foundation\Apache2.2 (Assuming default Apache installation).
  3. Edit httpd.conf.
  4. Add the following line:
    LoadModule python_module modules/mod_python.so
  5. Configure your Apache <Directory> directives to include AddHandler, PythonHandler, and PythonDebug (examples below).

To test your mod_python installation:

  1. Create a file named mptest.py in say C:\sites.
  2. The file will contain:
    from mod_python import apache
    def handler(req):
      req.content_type = ‘text/plain’
      req.write(”Hello World”)
      return apache.OK
  3. Edit httpd.conf.
  4. Under <Directory “C:/sites”> directive add:
    AddHandler mod_python .py
    PythonHandler mptest
    PythonDebug On
  5. Restart Apache and point your browser to the mptest.py url.