Setting up Mercurial 2.2 on IIS7

Jeremy Skinner has a good guide to setting up Mercurial 1.4/1.5 on IIS7, there are a few updates to the process for Mercurial 2.2 which are detailed below.

These instructions are based on a Windows 2008 R2 Datacentre install, with IIS7 already installed and setup. The server is 64bit, but I’m using the 32 bit versions of all the installers.

  1. Install Python 2.6.6. Using the MSI and default settings.
  2. Install Mercurial 2.2.1 (32 bit exe).
  3. Install Mercurial 2.2.1 (32 bit py2.6).Ensure you are using the py2.6 version, marked as “recommended for hgweb setups”. This installs the mercurial source as python scripts.
  4. Ensure CGI and Basic Authentication are installed for IIS. You can check this in Server Manager. If either are listed as “Not Installed” click “Add Role Services”. Click “Next”, then “Install” to complete the installation.

  5. Create a new site in IIS. This could be a virtual directory, but I prefer to have a separate site running off an arbitrary port (8989 in this case). Remember to add any additional firewall rules.
  6. As the site will be using Basic Authentication, it’s also a good idea to force it to run under SSL, even if it is only using a self signed certificate.
  7. Change the authentication options for the site to disable “Anonymous Authentication” and enable “Basic Authentication”. This will require all visitors to login before being able to use repositories.
  8. Enable Python for IIS. Select “Handler Mappings” for your site, and then “Add Script Map”.Enter the following values:
    Request path: *.cgi
    Executable: C:\Python26\python.exe -u “%s”

    Click OK, When prompted select “Yes”.



  9. Copy the “Templates” folder, and the “” file from “C:\Program Files (x86)\Mercurial” to the website root.
  10. Get a copy of the hgweb.cgi file from the Mercurial Repository, and copy it to the website root.
  11. Create a new file named “hgweb.config”, leave this empty for now. Update the config variable in “hgweb.cgi” to point to this new file, for example:config = “C:\Mercurial\Website\hgweb.config”
  12. Visit, you should be prompted to login (with windows credentials from the server) and then see a page titled “Mercurial Repositories” with no repositories listed.
  13. Make a folder to contain your repositories, and make a new repository using the hg command line:hg init C:\Mercurial\Repositories\test
  14. Edit the “hgweb.config” file you created earlier, entering the following content:
    C:\Mercurial\Repositories = C:\Mercurial\Repositories
    allow_push = *
    push_ssl = true
    N.B. The collections file path is case sensitive
  15. Reload the page, you should now see your “test” repository listed

The repository is now ready to use! As a self signed SSL certificate is used you will need to ensure you enable “insecure” mode when using hg/TortoiseHg.

One thought on “Setting up Mercurial 2.2 on IIS7

  1. Ben June 14, 2012 / 10:45 am


    If someone has some 502.2 error in following your guide (which is the clearest i could find) in trying to accessing the mercurial repositories page (point 12), you can fix it in replacing c:\whatever\Python26\python.exe -u “%s” “%s” to c:\whatever\Python26\python.exe -u -O -B “%s” “%s” for the point 8 (in handler mappings for the python script map).

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s