views:

4878

answers:

9

I've been looking all over for decent instructions on how to get hgwebdir working on IIS but I haven't found much of worth.

There's this "step by step" on the Mercurial wiki, but it's not very good. There's also this and this, but again, I can't find good steps to lead up to where those get started.

+3  A: 

Use mercurial to clone the mercurial repository:

hg clone http://selenic.com/repo/hg

you will find hgwebdir.cgi at the top level. It should install like any other cgi script.

Aaron Watters
+22  A: 

You will need to download the hgwebdir.cgi file from the Mercurial source. You can download the source by running: hg clone http://selenic.com/repo/hg

Create a folder that will be your web application folder. You will need to copy three things into this folder:

  • The hgwebdir.cgi file
  • The contents of the Library.zip from your "C:\Program Files\Mercurial" folder
  • The Templates folder from your "C:\Program Files\Mercurial"

You will also need to install Python. Then you need to make sure you have Python set up in IIS. Following these instructions worked for me for that, except make sure the application points to the folder you created, and also set the Request path to "*.cgi" instead of "*.py".

You will also need to create a file named "hgweb.config" with contents similar to below and place it in your application folder. The path within the file needs to be the location on your drive where you store the Mercurial repositories.:

[collections]
\Mercurial\repos = \Mercurial\repos

Now, open a browser and navigate to http://localhost/mercurial/hgwebdir.cgi (or whatever is the appropriate URL path you set up in IIS) and you should see the Mercurial Repositories page.

jwanagel
I've used these directions to set Mercurial and IIS up under XP (Professional). The index shows up, but if I click any of the repository links I get a 404 error. Any suggestions?
Brad Bruce
Found IT!!!!When setting up the .cgi mapping the Executable entry should readc:\Python25\python.exe -u "%s"and MAKE SURE Check that file exists is UNCHECKED!!!!!!
Brad Bruce
These instructions are a bit outdated now. Check out Ken's answer for more updated instructions: http://stackoverflow.com/questions/818571/how-to-setup-mercurial-and-hgwebdir-on-iis/2766947#2766947
firedfly
+10  A: 

There's a fairly good and comprehensive tutorial here: http://vampirebasic.blogspot.com/2009/06/running-mercurial-on-windows.html

Ben Schwehn
This blog post is a great start, but falls somewhat short. I wrote a fairly extensive set of blog posts about hosting Mercurial on IIS - see my answer below: http://stackoverflow.com/questions/818571/how-to-setup-mercurial-and-hgwebdir-on-iis/3320908#3320908
BenAlabaster
+1  A: 

The hg red book contains some much better general instructions than I've seen in other places. They are not IIS specific, but they are quite good:

http://hgbook.red-bean.com/read/collaborating-with-other-people.html#sec:collab:cgi

Kevin Berridge
+9  A: 

Below are what I did after doing a fair amount of research for geting hgwebdir.cgi setup on IIS6 . It is based on the following sites:

You'll need to install the following on the server:

  • Mercurial (I used version 1.5)
  • Python 2.6. The version of Python depends on the version of Mercurial installed. Mercurial 1.5 uses Python 2.6. Install x86 even if you are running x64.

The steps for me were:

  • Create a directory for the website. I used c:\inetpub\wwwroot\hg.
  • In IIS, right click on the folder for hg, select properties, select the Home Directory tab.
  • Click on the Create application button. Set the execute permissions to "scripts".
  • Still in the Home Directory tab, click on the Configuration button. In the "Application Configuration" popup, click the Add button to add an application extension. The Executable is c:\Python26\python.exe -u "%s" "%s". The extension is .cgi. Set the "verbs" to "limit to: GET,HEAD,POST". Check both Script engine and Verify that file exists.
  • In the Directory Security tab, click on the Edit button in the Authentication and access control section. Uncheck all authentication methods, and check the "Basic authenication" method. Set the Default domain if you like to your Active Directory domain.
  • In IIS, click on the Web Service Extensions folder on the left panel. Click on "Add a new Web service extension" link. Extension name should be Python, the required file is c:\Python26\python.exe -u "%s" "%s". Make sure the new extension is "Allowed".

Now is a good time to test that Python is working. Create a file in your new Hg folder called test.cgi. Paste the following python code:

print 'Status: 200 OK'
print 'Content-type: text/html'
print

print '<html><head>'
print ''
print '<h1>It works!</h1>'
print ''
print ''

Open the browser to your site, for instance, http://localhost/hg/test.cgi

You should see "It works!" in the browser.

Next let's get the hgwebdir working.

  • Delete test.cgi
  • clone the hg repo to a new directory: hg clone http://selenic.com/repo/hg
  • copy hgwebdir.cgi to your web directory: c:\inetpub\wwwroot\hg\ from the cloned hg repo
  • Edit the file and change
application = hgwebdir('hgweb.config')
wsgicgi.launch(application)

to

application = hgwebdir('c:\inetpub\wwwroot\hg\hgweb.config')
wsgicgi.launch(application)
  • Unzip the Library.zip file in the Mercurial directory, c:\Program Files\Mercurial\, to your web directory, c:\inetpub\wwwroot\hg\
  • Copy the templates directory from c:\Program Files\Mercurial\templates\ to c:\inetpub\wwwroot\hg\templates\
  • Create a file called hgweb.config in your web directory.

Now is a good time to test it out. Go to the following URL in the browser, http://localhost/hg/hgwebdir.cgi

  • Edit hgweb.config, and paste the following:
[collections]
\\server\share$\Hg\ = \\server\share$\Hg\
[web]
allow_push = *
push_ssl = false

These are all my preferences, for instance we have our repos in subdirectories at \\server\share$\Hg. The web app will run under the permissions of the logged in user via the browser, so they'll need read/write permissions to the share.

The last step is to allow for long connections which can happen when you first clone a repo. Run the following command to increase the timeout to 50 minutes:

cd \inetpub\AdminScripts\
cscript adsutil.vbs GET /W3SVC/CGITimeout 
cscript adsutil.vbs SET /W3SVC/CGITimeout 3000
Clay Lenhart
+15  A: 

It seems since Mercurial 1.5.2 was released, these tutorials don't work exactly right. For one thing, hgwebdir.cgi has been removed, and is now replaced with hgweb.cgi.

The instructions that worked best for me is at eworldui.net:

http://www.eworldui.net/blog/post/2010/04/08/Setting-up-Mercurial-server-in-IIS7-using-a-ISAPI-module.aspx

Those instructions are meant for IIS 7 or greater. If you're setting this up on IIS 6, I wrote up similar instructions geared toward Win2k3 and IIS 6.0:

http://partialclass.blogspot.com/2010/05/setting-up-mercurial-server-on-win2k3.html

Ken Pespisa
I originally tried to get things configured with Jeremy Skinner's tutorial and ran into issues with hgwebdir.cgi being removed. Using the IIS7 tutorial, I was able to get things setup with any complications. Thanks!
firedfly
Excellent -- thanks for pointing out these very useful references, Ken P.
Ken
+1  A: 

Link submitted by Ken worked great for me. Couldn't bump it up, so I thought I'd share this way.

mhl666
+6  A: 

I found that the blog post at Vampire Basic was a good start, but it didn't go into nearly enough detail for what I was after.

I did a 4 part blog post on this that gets you up and running from scratch with IIS, including Active Directory integration, setting up of security privileges for push/pull, customization of the template, I'd reproduce it here, but it's quite long winded being that Mercurial was really designed to be hosted on Linux/Apache:

http://www.endswithsaurus.com/2010/05/setting-up-and-configuring-mercurial-in.html

BenAlabaster
@BenAlabaster Wow - I wish I could upvote this to the top! Very well done. Any reason you didn't just use the URL Rewrite module from http://www.iis.net/download/URLRewrite ???
Goyuix
@Goyuix - Thanks, there's 2 reasons I didn't use that - 1. I had no idea it existed and nobody pointed me in that direction. 2. The little amount of research I did turned up ISAPI Rewrite which sufficed for the purpose I was using it for, so that's what I ended up using. Thanks for pointing that out though, I'll check it out.
BenAlabaster
@Goyuix - The info you pointed me to suggests that IIS URL Rewrite is for IIS 7? Is this available for IIS 6? My blog post was targeted at IIS 6 as that's what I was/am currently using.
BenAlabaster
This is an awesome series of posts. You should definitely do a follow up for IIS 7
BobTheBuilder
@BobTheBuilder - I'm planning on it, but I've gotta find time to upgrade my server to Win2K8, for the moment I'm on Win2K3 which tbh has sufficed for my needs and has been pretty solid, so I've had no requirement to upgrade.
BenAlabaster