By using this site you agree to the use of cookies.

Learn more

Share via:


Installing Mod_wsgi and Python for Apache on Windows

Tutorial on how to install Mod_wsgi and Python for use with the Apache HTTP Server.

Edited: 2018-02-25 04:08

Mod_wsgi and Apache, Windows

This tutorial deals with the installation of Mod_wsgi on Windows, which is a module to host python applications. To get started you first need to download the files corresponding to your version of Apache.

Windows Binary downloads are available from:

Link to Mod_wsgi's GitHub page:

Installing Mod_wsgi for Apache on Windows

Apache2.2 needs which you should rename to and place into your apache modules directory. Of cause this depends on where you installed Apache, but as an example this could be:

C:\Program Files\Apache Software Foundation\Apache2.2\modules

For simplicity, create a new directory outside your htdocs, simply name the new directory wsgi_app for now, and place it in c:

The final path to your new directory should look like:


Configure Mod_wsgi in Apache on Windows

The nest step is to configure Apache to run a basic test application from the directory you just made. So you will have to find your http.conf file, located in:

C:\Program Files\Apache Software Foundation\Apache2.2\conf

Open the file with your favorite editor, and insert the below:

LoadModule wsgi_module modules/

You can do a search for LoadModule, and place it directly below any other modules that you load. Otherwise, simply place it at the end of the file, so that you can easily find it later.

You should now create a WSGI script alias, this is used to direct requests to your new application. The below would direct requests for /wsgi to a file placed in your wsgi_app directory. But you should also create a directory block for your wsgi_app directory, both demonstrated below.

WSGIScriptAlias /wsgi "C:/wsgi_app/"
<Directory "C:/wsgi_app">
AllowOverride None
Options None
Order deny,allow
Allow from all

Again, for simplicity, you may want to find the section in the file, where the other Directory settings are located, and then place the above below the <Directory "C:/Program Files (x86)/Apache Software Foundation/Apache2.2/htdocs"> block.

Your first Python web Application

Create a file named inside of your wsgi_app directory. Then open this file in your editor, and add the below code to the file.

def application(environ, start_response):
    status = '200 OK'
    output = 'This is my Website!'

    response_headers = [('Content-type', 'text/plain'),
                        ('Content-Length', str(len(output)))]
    start_response(status, response_headers)

    return [output]

All you need to do now is to restart your Apache web server, and try and type in either, or localhost/wsgi (depending on your setup), to see if things work.