How to Install MoinMoin on IIS

I recently was posed the challenge of getting a Python Wiki running on my web server. Allright, I admit - the Python part was my choice.

Since I run a Windows web server, and I already run my CherryPy web site behind IIS with isapi-wsgi, and MoinMoin has WSGI support, I thought it might be possible to serve MoinMoin from IIS.

As it turns out, it's not that difficult. This article describes the steps I took.

Before we get started, you need to install some prerequisites to match my configuration. These are not requirements, but what I used to make this work.
- Windows Server 2008 SP2 64-bit
- Python 2.6.4 64-bit
- pywin32 214 64-bit
- distribute

First, you want to install the MoinMoin package somewhere. For simplicity, and because I already have distribute in my Python 2.6 install, I just ran 'easy_install MoinMoin==1.8.5'. Distribute found the tar file, unpacked it, and added it to my installation. Note that a better approach might be to keep MoinMoin installed outside of your core Python install, but that's outside the scope of this article.

I then downloaded the MoinMoin 1.8.5 tar.gz distribution and expanded the /moin-1.8.5/wiki directory to c:\InetPub\DemoWiki. If you don't already have 7-zip, I highly recommend it for .tar.gz files and similar. It's possible you could also have copied the wiki files from %python%\lib\site-packages\moin-1.8.5-py2.6.egg\share, but I haven't tried. The files don't have to be in C:\InetPub, but they will have to be accessible by the anonymous IIS user and the Application Pool Identity, so unless you know what you're doing, I recommend creating the site in C:\Inetpub.

The next step was to configure the site in IIS. If you're an IIS user, you've probably done this a hundred times. Here's what I did on my Windows Server 2008 running IIS 7. In the Internet Information Services Manager, I created a new site called "My Demo Wiki", and set the home directory to C:\Inetpub\DemoWiki (or wherever the wiki files were expanded in the previous step).

Next, you need a hook script that the pywin32 isapi module will use to launch the wsgi app. This script does a few things:

1. Handles command line arguments to install and uninstall the ISAPI Extension dll to/from the web site.
2. When the __ExtensionFactory__ is called, links to the MoinMoin configuration, creates the WSGI app, wraps it using isapi-wsgi, and returns it to IIS as an extension.

The script I ultimately created can be found at Note that this file cannot contain a period before the .py extension or it will fail.

This script was set up to install the wiki to the root of the newly-created web site. This all would work very well except that the MoinMoin wsgi server isn't set up to serve the static content. The Apache docs describe how to configure Apache to serve the static content, so I decided to work out how to get IIS to do the equivalent.

The default ISAPI-WSGI handler automatically passes all requests to the WSGI application, so I wanted a way to allow certain URLs to be bypassed by the ISAPI Extension. I found a great example of this in the redirection samples in the pywin32\isapi\samples. Based on these samples, I implemented a isapi_exclude module, which I placed in the same directory as the hook script (though I could have installed it anywhere in the Python path). This module defines a PathExclusionFilter, which will wrap an isapi ThreadPoolExtension and will defer any requests that match specified URLs to the lower-priority handlers. In other words, it allows paths to be ignored by the wrapped extension.

Next, the PathExclusionFilter was applied to the WSGI handler in configured to ignore /moin_static185 (the path that MoinMoin expects by default to access static content).

Next, since /moin_static185 doesn't exist in the IIS site, use IIS Manager to create a virtual directory in the site to C:\InetPub\DemoWiki\htdocs.

Then, give the IIS anonymous user ("IUSR") and also the Application Pool Identity (in this case, "IIS AppPool\My Demo Wiki") appropriate permissions to \InetPub\DemoWiki. For simplicity, I install Full Permissions. It's likely some more limited set would be adequate, but for now I install excessive permissions for simplicity. These commands will assign those permissions.

icacls C:\Inetpub\DemoWiki /grant "IIS AppPool\My Demo Wiki:(OI)(CI)(IO)(F)"
icacls C:\Inetpub\DemoWiki /grant "IUSR:(OI)(CI)(IO)(F)"

Finally, install the extension. To do this, run " install".

This final step copies a .dll to the DemoWiki directory, and installs it into IIS. Make sure you've stopped other web sites in IIS and enabled the My Demo Wiki site. Finally, you should be able to access http://localhost and get the MoinMoin welcome page.

My plans now are to contribute these various scripts back to the various projects and create a more simplified process. In the meantime, feel free to use any of these files or techniques to get MoinMoin running on your IIS server.
Written on December 1, 2009