Thursday, March 10, 2011

Mercurial on IIS with basic Active Directories

Notes on how to install Mercurial on Windows Server 2008  with basic Active Directory authentication.

Credit to Jeremy Skinner and Ben Alabaster who wrote the original articles on this.
This is an updated combination of the 2 posts, using the latest compatible versions of Python and Mercurial, and one or 2 steps that wheren't included in either post.


  1. Download and install Mercurial (mercurial-1.8.0)
    1. Seems to require 32 bit even on 64 bit systems
    2. Select defaults
  2. Download and install Python (python-2.6.6)
    1. Seems to require 32 bit even on 64 bit systems
    2. Select defaults
    3. Add C:\Python26\ to system PATH
  3. Download and install MinGW (mingw-get-inst-20110211)
    1. Use pre-package repsoitory catalogues
    2. Install to C:\minGW
    3. Don't create start folder
    4. Select C++ compiler 
    5. Add C:\MinGW\bin to the system PATH
  4. Download Mercurial Python Library (http://mercurial.selenic.com/release/mercurial-1.8.tar.gz)
    1. Extract folder
    2. jump into the command line where you extracted the library to
    3. execute "python setup.py install build --compiler=mingw32"
  5. Install and setup IIS
    1. Server Manager > Roles > Add Roles > Install IIS
    2. Server Manager > Role Services > CGI (enable)
    3. Create hg directory
      1. mkdir c:\inetpub\wwwroot\hg
    4. IIS Manager > Sites > Default web Site > Refresh
    5. IIS Manager > Sites > Default web Site > Bindings > http port 40
    6. IIS Manager > Sites > Default web Site > hg > Handler Mappings > Add Script Map
      1. Request Path: *.cgi
      2. Executable: C:\Python26\python.exe
      3. Name: Python
      4. Yes on dialog box that appears
    7. IIS Manager > Sites > Default web Site  > START
  6. Setup the Mercurial Web
    1. mkdir c:\temp\hgClone
    2. cd c:\temp\hgClone
    3. hg clone http://selenic.com/report/hg
    4. copy hg\hgweb.cgi c:\inetpub\wwwroot\hg
    5. cd c:\
    6. rmdir /S /Q c:\temp\hgClone
    7. c:\>"c:\Program Files\Windows NT\Accessories\wordpad.exe" c:\inetpub\wwwroot\hg\hgweb.cgi
      1. Change the line "application = hgweb(config)" to "application = hgweb('c:\inetpub\wwwroot\hg\hgweb.config')"
    8. extract C:\Program Files\Mercurial\library.zip into c:\inetpub\wwwroot\hg\library\
    9. copy C:\Program Files\Mercurial\templates\ to c:\inetpub\wwwroot\hg\
  7. Initialize Repositories
    1. mkdir c:\repositories
    2. mkdir test 
    3. hg init test
  8. Configure
    1. add to C:\inetpub\wwwroot\hg\hgweb.config:
      1. [collections]
        C:\repositories = C:\repositories
  9. URL Rewriting
      1. download http://www.iis.net/expand/URLRewrite
    1. install
    2. IIS Manager > Sites > Default web Site > URL Rewrite > new Rule > blank Rule
      1. name: Rewrite to hgweb
      2. Match URL
        1. Requested URL: Matches the Pattern
        2. Using Wildcards
        3. Pattern: *
        4. ignore case: yes
      3. Conditions
        1. Logical Grouping: Match All
        2. Add Condtion
          1. Condition input: {REQUEST_FILENAME}
          2. Check if input string: Is Not a File
      4. Action
        1. Action Type: Rewrite
        2. Action Properties
          1. Rewrite URL: /hg/hgweb.cgi/{R:1}
          2. Append Query String: Yes
          3. Log rewritten URL: No
        1. Stop processing of subsequent Rules: No
  10. Authorisation Settings
    1. IIS Manager > Sites > Default web Site > Authentication
      1. Disable Everything
      2. Enable Basic
      3. Edit Basic
        1. default domain: yourdomain.com
    2. Edit c:\inetpub\wwwroot\hg\hgweb.config
      1. add line
        1. push_ssl = false
      2. add line 
        1. allow_push = <comma seperated list of developer domain names>