mod_wsgi

Install

Windows

mod_wsgi (Linux)

sudo apt-get install libapache2-mod-wsgi

mod_wsgi (Windows)

  • Download mod_wsgi.so from http://adal.chiriliuc.com/mod_wsgi/.

    I downloaded from this folder, http://adal.chiriliuc.com/mod_wsgi/revision_726_2.0c4/mod_wsgi_py25_apache20/ (The latest revision for python 2.5 and Apache 2.0).

  • Copy mod_wsgi.so to the Apache modules folder.

    On my workstation:

    copy \download\apache\mod_wsgi.so \tools\Apache2\modules\
    
  • Load the wsgi module.

    Edit the Apache configuration file, conf/httpd.conf and add:

    LoadModule wsgi_module modules/mod_wsgi.so
    

    If you want to, change the logging level:

    LogLevel info
    
  • Restart Apache.

    Check the logs/error.log file. It should contain some references to python and WSGI…

Test

  • Create a folder to contain your WSGI applications. I created:

    C:\repository\apache\python\wsgi\
    
  • Create the python script my-wsgi-app.wsgi in this folder. Here is the script:

    def application(environ, start_response):
        status = '200 OK'
        output = 'Hello World!'
        response_headers = [('Content-type', 'text/plain'),
                                ('Content-Length', str(len(output)))]
        start_response(status, response_headers)
        return [output]
    
  • Edit conf/httpd.conf and add one of the following:

    • For a single application:

      WSGIScriptAlias /myapp "C:/repository/apache/python/wsgi/my-wsgi-app.wsgi"
      <Directory "C:/repository/apache/python/wsgi">
        Order allow,deny
        Allow from all
      </Directory>
      

      The following URL should run the application: http://localhost/myapp

    • To run multiple applications from a folder:

      WSGIScriptAlias /wsgi/ "C:/repository/apache/python/wsgi/"
      <Directory "C:/repository/apache/python/wsgi">
        Order allow,deny
        Allow from all
      </Directory>
      

      Allows access to multiple application in a folder. In this example, the url http://localhost/wsgi/my-wsgi-app.wsgi will run our test application.