Installing Mercurial on Server 2008 R2 with IIS

I use Mercurial to version all of my scripts at work, and have a general preference for using IIS over Apache on Windows.  Problem is that finding detailed instructions for installing Mercurial on Server 2008 R2 using IIS were hard to come by.  I found some excellent instructions for 2003 on the Vampire Basic blog but they required some modification for use on 2008 R2.  Below are the basic steps that I used for installing Mercurial 1.5.1 on a 2008 R2 VM.  One of the advantages of using IIS is that its easier to native authentication for Mercurial access control.

These instructions will give you a Mercurial install that uses IIS sharing out repositories located at E:\Repositories.  Remote push is enabled, and is secured via the use of NTFS permissions on the individual repository folders.  These instructions are about 7 months old and it looks like most of the software has been updated now, when I upgrade my server I will revise these instructions as necessary.

  1. Install Server 2008 R2
    1. Enable Remote Access
    2. Set hostname
    3. Join domain
    4. Add E:\ disk in Disk Manager
    5. Enable Web Server Role
    6. Add to default selections:
      • HTTP Redirection
      • CGI
      • Logging Tools
      • Tracing
      • Basic Authentication
      • Windows Authentication
      • URL Authorization
      • IP and Domain Restrictions
      • IIS Management Scripts and Tools
  2. Install URL Rewrite 2.0 x64 (Download)
  3. Install TortoiseHg 2.0.0 x64 (Download)
    1. Install to E:\Program Files\TortoiseHg\
    2. Accept Installer Defaults
  4. Install Mercurial 1.8 (Download)
    1. Install to E:\Program Files\Mercurial\
    2. Accept Installer Defaults
  5. Install Python 2.6.6 (x86) (Download)
    1. Install for All Users
    2. Install to E:\Apps\Python26
    3. Accept Installer Defaults
  6. Configure Proxy in IE if required
  7. Clone Mercurial Source Files
    1. launch Admin CMD prompt and execute these commands
      1. If required, set http_proxy=proxy.example.com:8080
      2. Change to E:
      3. mkdir Repositories
      4. cd Repositories
      5. hg clone http://selenic.com/repo/hg
      6. mkdir e:\Apps\hgcgi
      7. copy hg\hgweb.cgi e:\apps\hgcgi
      8. xcopy e:\Program Files\Mercurial\templates\* e:\apps\hgcgi\templates /E /I
      9. write e:\apps\hgcgi\hgweb.cgi
        1. Change the config line to be and save/close the file
          Config = "e:/apps/hgcgi/hgweb.config"

          1. In Windows Explorer
            1. Extract E:\Program Files (x86)\Mercurial\Library.zip to E:\Apps\hgcgi
        2. Configure hgweb.cgi
          1. Create new file called hgweb.config in e:\apps\hgcgi with below contents
            [paths]
            / = E:\Repositories\**
             
            [web]
            style = monoblue
            baseurl = /hg
            push_ssl = false
            allow_push = *
             
            [extensions]
            hgext.notify =
             
            [hooks]
            changegroup = hg update >&2
            changegroup.notify = python:hgext.notify.hook
             
            [email]
            from = mercurial@example.com
             
            [smtp]
            host = smtp.example.com
             
            [notify]
            sources = serve push pull bundle
            test = false
            config =
            template = Subject: {webroot|basename}: {desc|strip|firstline}\n\ndetails:   {baseurl}{webroot|basename}/rev/{node|short}\nchangeset: {rev}:{node|short}\nuser:      {author}\ndate:      {date|date}\ndescription:\n{desc}\n
             
            [usersubs]
            developer@example.com = *

Launch IIS Manager

  1. Select Application Pools
  2. Add Application Pool
    • Name: hg
    • .NET framwork: No Managed Code
    • Click OK
  3. Select Default Web Site
  4. Add Application
    • Alias: hg
    • AppPool: hg
    • Path: e:\apps\hgcgi
  5. Select new hg virtualdir
    1. Edit Handler Mappings
    2. Add Script Map
      1. Properties
        • Request path: hgweb.cgi
        • Executable: E:\Apps\Python26\python.exe -u %s %s
        • Name: Mercurial CGI
      2. Modify Request Restrictions
        1. Select Access Tab
        2. Select Execute
        3. Click OK
      3. Click OK
      4. Enable ISAPI application: Yes
    3. Right click Mercurial CGI mapping
    4. Select Edit Feature Permissions
      1. Select Execute
      2. Click OK
  6. Import These URL Rewrite Rules
    RewriteRule ^$ hgweb.cgi  [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule (.*) hgweb.cgi/$1  [QSA,L]
This entry was posted in Development. Bookmark the permalink.