Part 1: Setting up and configuring Mercurial for IIS
This blog post is part of a four part series for getting Mercurial up and running in a Windows environment and hosting it on IIS 5.1 (i.e. Windows Server 2003).
- Part 1 Getting Mercurial set up in IIS and hosting a repository at http://hg.mydomain.com/
- Part 2 Getting IIS to hide hgwebdir.cgi in the URL for your Mercurial repositories.
- Part 3 Locking down security using Active Directory so that only authorized users can view, clone, pull and/or push to a repository.
- Part 4 Customizing the theme/skin of the web interface of your Mercurial repositories.
If you haven't checked out http://vampirebasic.blogspot.com/2009/06/running-mercurial-on-windows.html which should get you up and running, you should. I want to gloss over most of the steps very quickly, but I also want to flesh out a few bits that I feel were unclear or could do with some further detail.
- Download and install Python - I've only tested with Python 2.6
- Download and install Mercurial.
- Download and install TortoiseHg - I'm told that some of the bindings for Active Directory don't work with the version of hg.exe that comes with Mercurial. If you're not going to use Active Directory, don't worry about this step.
- Modify your path in Environmental variables. Remove the path to the Mercurial bin and replace it with the path for TortoiseHg. Again, if you're not going to be using Active Directory for authentication, this step is not needed.
- Create a directory that's going to host your Mercurial/IIS install. I'll refer to this directory as MercurialWeb (I will also refer to its fully qualified domain name as http://MercurialWeb as this will differ for each website).
- Unzip the library folder in your TortoiseHg folder to MercurialWeb.
- Copy the whole templates folder from the Mercurial install directory to MercurialWeb.
- Open Internet Information Services from Administrative tools.
- Click Web Service Extensions.
- Click the "Add a new Web service extension" link.
- Add the extension name Python
- Add the required file <PythonInstallDir>\python.exe -u "%s" "%s"
- Check the Set extension status to Allowed
- Either create a new website or a new virtual directory pointing to MercurialWeb.
- Click the Home Directory tab.
- Click the Configuration button.
- Click Add...
- Set the executable to <PythonInstallDir>\python.exe -u "%s" "%s"
- Set the extension to .cgi
- Limit verbs to GET,HEAD,POST
- Make sure Script engine is checked
- It doesn't seem to make any difference if Verify that file exists is checked or not.
- Click OK
- Click OK
- Click OK
Now you should be able to access MercurialWeb. That's great, but we don't have any repositories hooked up to it, so it's not very useful right now.
Lets create a repository to be hosted on MercurialWeb. So create a folder somewhere on your hard drive [Caveat: The folder must be on the same partition as your MercurialWeb directory - i.e. if your MercurialWeb folder is hosted on D: then your repo must be somewhere on D: too].
Initialize it as a repository... you can either do this through the TortoiseHg shell extension for explorer by right clicking, selecting TortoiseHg/Create Repository Here or you can do it from the command line:
C:\Documents and Settings\balabaster\>d: D:\>mkdir MercurialRepos D:\>cd MercurialRepos D:\MercurialRepos\>hg init
Next we need to tell MercurialWeb that we want this repository included in our repo list. So open your MercurialWeb directory and find a file called hgweb.config. Don't worry if the file isn't there, just create one, it's just a plain text file.
We can either add collections of repositories - i.e. by adding the common root to the [collections] section, or we can add specific repositores explicitly in the [paths] section. If the relevant section is missing, just add it.
[collections] \Mercurial\Repos = /Mercurial/Repos \SomeOtherFolderContainingABunchOfRepos = /SomeOtherFolderContainingABunchOfRepos \Path\To\Another\Set\Of\Repos = /Path/To/Another/Set/Of/Repos
Or for static repositories:
[paths] Project1 = D:\Projects\Project1 Project2 = D:\Path\To\Project2 Project3 = D:\Another\Path\To\Project3 ...
Save the file and you should now be able to access your repositories using something similar to http://MercurialWeb/hgwebdir.cgi/Project1.
The next step is to hide hgwebdir.cgi...