Tuesday, May 04, 2010

Setting up a Mercurial server on Win2k3 / IIS 6.0

There are several tutorials right now explaining how to setup a Mercurial server in Windows, but most are outdated just enough to make the whole process fail due to recent changes to Mercurial.  I tried a few, but the best one available as of Mercurial 1.5.2 is from Matt Hawley from eWorldUI.net.  His post explains how to set up the server using IIS 7.0, and the process is slightly different in IIS 6.0, as I’ll explain.

First, read his blog post to get a sense of the procedure.  The post is broken into two major sections, Packages Installation, and Configuration.  I followed the Packages Installation section exactly as written, with the exception of downloading the latest source for Mercurial, which is 1.5.2. 

Once you’ve completed the Packages Installation, follow these steps instead to configure IIS 6.0.  Many of these steps are the same as Matt describes, but for convenience I’ve duplicated them here.  All credit for this goes to Matt for getting us 99% of the way there. 

These steps assume you have IIS installed already.

  1. Create a folder to host your Mercurial site.  As Matt suggests, you can use c:\inetpub\hg
  2. Copy the hgwebdir_wsgi.py file from c:\(mercurial source code location)\contrib\win32 to c:\inetpub\hg
  3. Edit hgwebdir_wsgi.py in a text editor and change the two lines as follows:

    hgweb_config = r’c:\inetpub\hg\hgweb.config’
    path_prefix = 0
  4. Open a command prompt and go to the c:\inetpub\hg folder
  5. Run python hgwebdir_wsgi.py.  If python isn’t installed on the system path, you may need to include the path to it and use c:\python26\python hgwebdir_wsgi.py
  6. Create a new text file named hgweb.config in the c:\inetpub\hg folder and add the following.  Here c:\repos is the folder where you will store your repositories.

    / = c:\repos\*

    At this point, your folder should look like this:
  7. In IIS Manager, create a new application pool with the name Mercurial.
  8. Create a new website called Mercurial, and set the TCP port to 81 (or any unused port).  Leave the Host header field blank.
  9. Set the path to c:\inetpub\hg and finish the wizard.
  10. Right-click the Mercurial website and choose properties.
  11. On the Home Directory tab, click Configuration, and then click Insert… in the Wildcard application maps section.  Enter the path to the isapi dll (c:\inetpub\hg\_hgwebdir_wsgi.dll) and uncheck verify file exists.
  12. On the ISAPI filters tab, click Add… and enter Mercurial-ISAPI as the filter name and c:\inetpub\hg\_hgwebdir_wsgi.dll as the executable.
  13. Finally, go to the Web Service Extensions in IIS Manager and Add a new Web service extension.  Give it the name Mercurial-ISAPI, and add the required file c:\inetpub\hg\_hgwebdir_wsgi.dll, and check the “Set extension status to Allowed” option.
  14. Finally, browse to http://localhost:81 (or substitute 81 for the port you chose in step 8).  You should now see the Mercurial Repositories page!



BenAlabaster said...

I wrote an article on this a few months back that goes over some of the other steps that may be useful.


It was also written for Win2K3/IIS6 but it covers a couple of extra bits like hiding ugly URLs and customizing the web UI.

Ben Tsai said...

Does this work for IIS 5.1?

Ken Pespisa said...

I haven't tried but I imagine so