May 13, 2010

Setting up and configuring Mercurial in a Windows/IIS/Active Directory environment - Part 1/4

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).

  1. Part 1 Getting Mercurial set up in IIS and hosting a repository at
  2. Part 2 Getting IIS to hide hgwebdir.cgi in the URL for your Mercurial repositories.
  3. Part 3 Locking down security using Active Directory so that only authorized users can view, clone, pull and/or push to a repository.
  4. Part 4 Customizing the theme/skin of the web interface of your Mercurial repositories.

If you haven't checked out 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.

  1. Download and install Python - I've only tested with Python 2.6
  2. Download and install Mercurial.
  3. 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.
  4. 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.
  5. 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).
  6. Unzip the library folder in your TortoiseHg folder to MercurialWeb.
  7. Copy the whole templates folder from the Mercurial install directory to MercurialWeb.
  8. Open Internet Information Services from Administrative tools.
  9. Click Web Service Extensions.
  10. Click the "Add a new Web service extension" link.
  11. Add the extension name Python
  12. Add the required file <PythonInstallDir>\python.exe -u "%s" "%s"
  13. Check the Set extension status to Allowed
  14. Either create a new website or a new virtual directory pointing to MercurialWeb.
  15. Click the Home Directory tab.
  16. Click the Configuration button.
  17. Click Add...
  18. Set the executable to <PythonInstallDir>\python.exe -u "%s" "%s"
  19. Set the extension to .cgi
  20. Limit verbs to GET,HEAD,POST
  21. Make sure Script engine is checked
  22. It doesn't seem to make any difference if Verify that file exists is checked or not.
  23. Click OK
  24. Click OK
  25. 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.

\Mercurial\Repos = /Mercurial/Repos
\SomeOtherFolderContainingABunchOfRepos = /SomeOtherFolderContainingABunchOfRepos
\Path\To\Another\Set\Of\Repos = /Path/To/Another/Set/Of/Repos

Or for static repositories:

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...

No comments:

Post a Comment