How do I set up Mercurial and hgweb on IIS?
Asked Answered
G

9

73

I've been looking all over for decent instructions on how to get hgweb 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.

Gasman answered 4/5, 2009 at 2:8 Comment(7)
Why not start with the instructions on the wiki, then say where you hit problems. Plus, if you get it working you can correct the wiki.Sokul
The wiki is wrong for my windows install. There is no hgwebdir.cgi. Also it doesn't tell you where to get it, where to put it, etc. Mercurial is really lacking a good guide for IIS, which is where I was hoping StackOverflow might step in.Gasman
@Kevin Berridge - There's a walkthrough for Windows at vampirebasic.blogspot.com/2009/06/… This worked for me.Prestonprestress
I have written out and tested Current instructions how to setup Mercurial 1.8 64 bit on IIS7Eloisaeloise
@Eloisaeloise That link no longer worksOffice
Sorry brotha I have taken my website down and am in the process of rebranding it. But just because you asked and you are worthy as we are I have re-posted the page. Giver another go and lemmie know if it still workies. Peace in.Eloisaeloise
@Eloisaeloise link is not working againAffixation
N
49

I just had to install a fresh Mercurial instance yesterday, here's updated instructions for 1.7:

  1. Install Mercurial (these instructions were tested with 1.7)
  2. Install Python (for Mercurial 1.7, you must use the x86 version of Python 2.6.6)
  3. You will need to download the hgweb.cgi file from the Mercurial source. You can download the source by running: hg clone https://www.mercurial-scm.org/repo/hg/
  4. Create a folder that will be your web application folder. You will need to copy three things into this folder:

    • The hgweb.cgi file
    • The contents of the Library.zip from your "C:\Program Files\Mercurial" folder
    • The Templates folder from your "C:\Program Files\Mercurial"
  5. You will need to make sure you have Python set up in IIS.

    • Enable CGI via the following: Control Panel -> Turn Windows Features On or Off -> Roles -> Web Server (IIS) -> Add Role Services -> Check CGI
    • Create a new Web Site in IIS and make sure the physical path is the folder you created above
    • In the Handler Mappings for the new website, select "Add Script Map". Enter *.cgi for the request path, c:\Python26\python.exe -u "%s" for the Executable, and Python for the Name.
  6. You will also need to create a file named "hgweb.config" with contents similar to below. The path within the file needs to be the location on your drive where you want to store the Mercurial repositories:

    [collections]
    c:\Mercurial\repos = c:\Mercurial\repos

  7. Edit the hgweb.cgi file and change the line where it sets the path to your hgweb.config to something like the following (wherever the hgweb.config file is):

    config = "C:\Mercurial\hgweb.config"

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

Also, check out Jeremy Skinners blog post . It's a little outdated, but has some extra nice steps like setting up URL re-writing for cleaner URL's.

Noctilucent answered 20/5, 2009 at 9:12 Comment(4)
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?Presuppose
Found IT!!!! When setting up the .cgi mapping the Executable entry should read c:\Python25\python.exe -u "%s" and MAKE SURE Check that file exists is UNCHECKED!!!!!!Presuppose
These instructions are a bit outdated now. Check out Ken's answer for more updated instructions: #819071Coagulum
Can you include steps for bypassing the 30MB upload limit imposed by IIS? I've tried setting both maxAllowedContentLength and maxRequestLength but neither seem to be having an effect!Dramatic
B
34

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

UPDATE: Shortly after getting this working I learned that BitBucket changed their pricing scheme to offer free, unlimited, private hosting: https://bitbucket.org/. I would've opted for that in a heartbeat when I was originally working on this project.

Brande answered 4/5, 2010 at 16:8 Comment(1)
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!Coagulum
S
11

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: https://www.mercurial-scm.org/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
Southwestward answered 6/4, 2010 at 9:40 Comment(1)
+1 Great job, only need to change a few minor things for Mercurial 1.7Alphabetic
N
3

Use mercurial to clone the mercurial repository:

hg clone https://www.mercurial-scm.org/repo/hg/

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

Nickens answered 4/5, 2009 at 21:39 Comment(0)
U
2

I've been fighting with this setup for mercurial 1.7.2 for the past week or so, I had to do things slightly differently than the above articles do in order to get it working.

Posting here because google kept bringing me back here....

Full instructions posted here

I followed a combination of these instructions and these (in the source)

The main differences are that I had to do the "pure python" install of mercurial otherwise it would complain about missing dlls, and I found it was important to use the "python installers" for pywin and isapi-wsgi. (maybe this is obvious to experienced python developers, but I'm a python newbie so it was news to me)

Hope this helps somebody and I'm not just making stuff up (I might be, like i said, python newbie)

Ultan answered 6/12, 2010 at 15:5 Comment(0)
A
2

I really struggled getting Hg installed on Server 2019 and IIS 10. Here is what I did to get it working:

  1. Install Python 2.7 which in my case was python-2.7.18.amd64.msi. I will assume it's installed in C:\Python27. Make sure python is added to your path and that pip is installed.

  2. Install Mercurial as a module using pip at the command line:

    pip install mercurial
    
  3. Under Default Web Site add a new application called hg and point it to the directory you want to use.

  4. Configure Python as CGI handler in IIS 10.0 for this new website (or the entire web server if you wish). You can do this manually or create/add the follwing to your web.config file:

    <system.webServer>
        <handlers accessPolicy="Read, Script">
            <add name="Python 2.7" path="*.cgi" verb="*" modules="CgiModule" scriptProcessor="C:\Python27\python.exe -u &quot;%s&quot;" resourceType="File" />
        </handlers>
    </system.webServer>
    
  5. In the 'hg' application folder create a hgweb.cgi that looks similar to the following:

    #!/usr/bin/env python3
    #
    # An example hgweb CGI script, edit as necessary
    # See also https://mercurial-scm.org/wiki/PublishingRepositories
    
    # Path to repo or hgweb config to serve (see 'hg help hgweb')
    config = "hgweb.config"
    
    # Uncomment and adjust if Mercurial is not installed system-wide
    # (consult "installed modules" path from 'hg debuginstall'):
    # import sys; sys.path.insert(0, "/path/to/python/lib")
    
    # Uncomment to send python tracebacks to the browser if an error occurs:
    #import cgitb; cgitb.enable()
    
    from mercurial import demandimport
    
    demandimport.enable()
    from mercurial.hgweb import hgweb, wsgicgi
    
    application = hgweb(config)
    wsgicgi.launch(application)
    
  6. In the 'hg' application folder create the hgweb.config file and point it at your repos like the following:

    [collections]
    C:\Web\www\hg\repos\ = C:\Web\www\hg\repos\
    
  7. Navigate to http://localhost/hg/hgweb.cgi and enjoy!

Addlebrained answered 24/6, 2021 at 17:6 Comment(0)
G
1

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

Gasman answered 11/8, 2009 at 21:35 Comment(0)
E
1

I was running into a "...can not load module..." type error and after some reading, the key for me was to ignore the Library.zip file in the Mercurial folder, and instead use the one from C:\Program Files (x86)\TortoiseHg folder.

That tip I found as #6 in this guide:

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

Hope this helps someone...

Engenia answered 10/12, 2010 at 19:54 Comment(0)
T
-1

You can try HgLab. This isn't exactly hgwebdir; rather it is a purely managed Mercurial implementation with push and pull server and repository browser.

Tetryl answered 10/10, 2012 at 8:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.