Mercurial and hosting it as an ISAPI module under IIS6

After reading a bit more about Mercurial as a distributed source code control system, and discovering that it will co-exist with git I decided to try it out, so I could see which I prefer. The jury is still out at the moment, but I also decided to install mercurial on my windows home server so I could try hosting repos centrally. Here's the process I went through to get it set up, it took a bit of messing about to get working in IIS6 with ISAPI, mainly due to there not being many resources on the net for setting it up with ISAPI under IIS6.

First thing is to follow this great post by Matt Hawley, it has the links and instructions to set up all the required packages, python, pywin32, mercurial, and isapi-wsgi. Follow that post up to the config part.

Now my setup differs from Matts, he creates a new website to host mercurial and starts it on port 81, I wanted to use port 80/443 and have it play nicely with the rest of the WHS standard web sites, but I didn't want to have to configure host headers, and wildcard certs, etc. I discovered that using host headers were a problem too, apparently they mess up the existing software in my HP WHS, so I decided to go with a virtual directory under the main web page.

When modifying the 'hgwebdir_wsgi.py' file to set your hgweb_config path, I also set the path_strip and path_prefix to 1 rather than 0. It doesn't seem to work if you only set path_prefix to 1.

 

 

Follow Matt's instructions for generating the DLL shim called _hgwebdir_wsgi.dll.

I created a shared folder in WHS to contain the repos (because you can't access the drives directly that are used in the drive set), so set that path in hgweb.config file:

[paths]
/ = \\server\repos\*

In IIS Manager create a new app pool called Mercurial, then create a new virtual directory pointing to the folder you created in Matt's post step 1. (mine was c:\inetpub\hg, but it could be anywhere you like)

If you do use a network share for your repos, you will need to change the identity that the app pool uses to a user that has permissions to access that folder, or give access permissions to Network Service. If you change the identity to a local user, follow the instructions in this post for assigning the correct groups and rights to the user, otherwise you might just get a 'Service Unavailable' message when you browse to the page.

 

 

Click the configuration button to configure the application.

 

Click Insert in the Wildcard Application Maps and select the _hgwebdir_wsgi.dll file. Important! Ensure you uncheck the 'Verify that file exists' checkbox, otherwise you will get 404 errors when you try to browse the site.

 

 

In the directory security tab click the Edit button on the Authentication and Access Control and disable anonymous access, also enable basic authentication and disable integrated windows authentication. This is needed for mercurial authentication, but credentials are transmitted in plain text so shouldn't be used on the public internet without ssl.

 

 

To enable ssl, assuming your site already has a certificate etc, just click edit on the secure communications, and check the require secure channel checkbox.

 

Now you should be able to browse to https://yoursite/hg and see the repository summary page.