Setting Python Path in Windows XAMPP using WSGI Setting Python Path in Windows XAMPP using WSGI apache apache

Setting Python Path in Windows XAMPP using WSGI


My PC has Python 2.6, so I'll use all the configuration under the assumption that Python 2.6 is the target version.

  1. Download newest xampp (http://www.apachefriends.org/en/xampp-windows.html), as of Nov 29, 2010, ver 1.7.3 is the newest.
  2. Install xampp for windows, I installed it c:\xampp
  3. Download and install Python 2.6 (http://www.python.org/download/releases/2.6/)
  4. Download wsgi for windows - http://code.google.com/p/modwsgi/wiki/DownloadTheSoftware?tm=2Refer to the documentation if necessary - http://code.google.com/p/modwsgi/wiki/InstallationOnWindows
  5. Copy the so file to module directory C:\xampp\apache\modules, don't forget to rename it mod_wsgi.so
  6. Add the following line to C:\xampp\apache\conf\httpd.conf
    • LoadModule wsgi_module modules/mod_wsgi.so
  7. Relaunch apache using C:\xampp\xampp-control.exe

For testing I did the following steps.

  1. Make C:\xampp\htdocs\wsgi\scripts directory, and copy the test test.wsgi.

The test.wsgi is as follows.

#!/usr/bin/env python"""A simple WSGI test application.Its main purpose is to show that WSGI support works (meaning that theweb server and the WSGI adaptor / support module are configured correctly).As a nice plus, it outputs some interesting system / WSGI values as a niceHTML table.The main use of this script will be using the WSGI "application" definedbelow within your production WSGI environment. You will use some code similarto what you see at the end of this script to use the application from thatenvironment. For the special case of apache2/mod_wsgi, it shoud be possibleto directly use this file.If you start this script from the commandline either with python2.5 or withand older python + wsgiref module installed, it will serve the content onhttp://localhost:8000/ - this is mainly for debugging THIS script.@copyright: 2008 by MoinMoin:ThomasWaldmann@license: Python License, see LICENSE.Python for details."""import os.pathimport osimport systry:    __file__except NameError:    __file__ = '?'html_template = """\<html><head> <title>WSGI Test Script</title></head><body> <h1>WSGI test script is working!</h1> <table border=1>  <tr><th colspan=2>1. System Information</th></tr>  <tr><td>Python</td><td>%(python_version)s</td></tr>  <tr><td>Python Path</td><td>%(python_path)s</td></tr>  <tr><td>Platform</td><td>%(platform)s</td></tr>  <tr><td>Absolute path of this script</td><td>%(abs_path)s</td></tr>  <tr><td>Filename</td><td>%(filename)s</td></tr>  <tr><th colspan=2>2. WSGI Environment</th></tr>%(wsgi_env)s </table></body></html>"""row_template = "  <tr><td>%s</td><td>%r</td></tr>"def application(environ, start_response):    mysite = '/Users/smcho/Desktop/django'    if mysite not in sys.path:        sys.path.insert(0,'/Users/smcho/Desktop/django')    mysite = '/Users/smcho/Desktop/django/mysite'    if mysite not in sys.path:        sys.path.insert(0,'/Users/smcho/Desktop/django/mysite')    """ The WSGI test application """    # emit status / headers    status = "200 OK"    headers = [('Content-Type', 'text/html'), ]    start_response(status, headers)    # assemble and return content    content = html_template % {        'python_version': sys.version,        'platform': sys.platform,        'abs_path': os.path.abspath('.'),        'filename': __file__,        'python_path': repr(sys.path),        'wsgi_env': '\n'.join([row_template % item for item in environ.items()]),    }    return [content]if __name__ == '__main__':    # this runs when script is started directly from commandline    try:        # create a simple WSGI server and run the application        from wsgiref import simple_server        print "Running test application - point your browser at http://localhost:8000/ ..."        httpd = simple_server.WSGIServer(('', 8000), simple_server.WSGIRequestHandler)        httpd.set_app(application)        httpd.serve_forever()    except ImportError:        # wsgiref not installed, just output html to stdout        for content in application({}, lambda status, headers: None):            print content
  1. Make C:\xampp\apache\conf\other\wsgi.conf that has the following content

This is the code

<Directory "C:/xampp/htdocs/wsgi/scripts">  Options ExecCGI Indexes  AddHandler cgi-script .cgi  AddHandler wsgi-script .wsgi    Order allow,deny  Allow from all</Directory>Alias /wsgi/ "C:/xampp/htdocs/wsgi/scripts/"<IfModule wsgi_module>  WSGIScriptAlias /test "C:/xampp/htdocs/wsgi/scripts/test.wsgi"</IfModule>
  1. Add this line to the httpd.conf Include "conf/other/wsgi.conf"
  2. Relaunch apache.
  3. You'll see wsgi info when you enter 'localhost/test' or 'localost/wsgi/test.wsgi' in your web browser.


I also had the "server error", and went to see in the Apache error.log file: it was due to some white space or line break coming with the comment line "Its main purpose is to ..."