4 Comments
Quick and easy setup of Mercurial server on Windows
by Riverside Software
Installing Mercurial on a Linux server is a matter of minutes (depending on your Linux distro). But I had to install it on a Windows server, and there are subtle pitfalls you're likely to encounter when doing that. This post is by no mean a full and detailed installation process for every configuration, it will just focus on a simple install.Step 1 : HTTPD install
HTTPD is one of the widely used HTTP server. The Windows version can be downloaded from here. I'm using the 2.2.17 Win32 Binary including OpenSSL 0.9.8o. Choosing a typical install will use C:\Program Files (x86)\Apache Software Foundation\Apache2.2 as the default directory. The only specific step during install is this screen :
Just fill with appropriate values depending on your network.
Step 2 : Python install
Python is needed by Mercurial. You always have to use the same Python version as the one used by Mercurial. The current Mercurial version (1.7.5) is still using 2.6, so download this version from Python website. Even if you're running Win x64, download the x86 version as I encountered some bugs with the 64 bits package (no idea why). Use the default settings for everything (especially installation directory).
Step 3 : Mercurial install
Mercurial compiled for Windows can be downloaded from here. Never use TortoiseHg to setup a Mercurial server, it won't work correctly (and easily). Always download *.win32-py2.6.exe packages, they're easier to setup.
Setup should detect your Python version and so compile Mercurial with Python 2.6.
Step 4 : Create directory structure
This test installation will use 3 differents directories to host repositories. We will use subfolders of C:\Repositories , named /Production, /QA and /Dev
We will keep them empty for now, just create this structure.
Step 5 : HTTPD setup
Create a new file called hgweb.cgi in C:\Program Files (x86)\Apache Software Foundation\Apache2.2\cgi-bin with this content :
#!C:/Python26/python.exe -u
# See also http://mercurial.selenic.com/wiki/PublishingRepositories
# Path to repo or hgweb config to serve (see 'hg help hgweb')
config = "C:/Program Files (x86)/Apache Software Foundation/Apache2.2/cgi-bin/hgweb.config"
# Uncomment and adjust if Mercurial is not installed system-wide:
# import sys; sys.path.insert(0, "SomeDirectory")
# 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)
Create a new file called hgweb.config in C:\Program Files (x86)\Apache Software Foundation\Apache2.2\cgi-bin with this content :
Add this line in C:\Program Files (x86)\Apache Software Foundation\Apache2.2\conf\httpd.conf in the <IfModule alias_module=""> section :[paths]/Production = C:/Repositories/Production/*/QA = C:/Repositories/QA/*/Dev = C:/Repositories/Dev/*[web]allow_push = *style = monobluecontact = mercurial@riverside-software.frpush_ssl = false
This line allows HTTPD to map the /hg query directly to Mercurial (instead of calling /cgi-bin/hgweb.cgi).ScriptAlias /hg "C:/Program Files (x86)/Apache Software Foundation/Apache2.2/cgi-bin/hgweb.cgi
Don't forget to restart HTTPD.
Step 6 : Test !
Open your web browser at http://localhost/hg and voilĂ ! You should have this page :
Step 7 : Enjoy
You can now import/clone your repositories
June 15, 2012 at 2:17 AM
Thank you.
Thank you.
THANK YOU for posting this. I've been wading through the copious and obscure documentation on how to do this for several hours now, and this just worked.
You do have one flaw in you post, though. The section where you insert the ScriptAlias line is the 'IfModule alias_module' section, but you forgot to escape the < and > and it is blank.
June 15, 2012 at 2:17 AM
October 5, 2012 at 5:34 PM
I have tried to setup the mercurial using the above steps but facing problems when I run
http://localhost:8080/hg
Error :-
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator, admin@sdmnet.ca and inform them of the time the error occurred, and anything you might have done that may have caused the error.
More information about this error may be available in the server error log.
Softwares used -
httpd-2.2.17-win32-x86-openssl-0.9.8o.msi
mercurial-2.3.2.win32-py2.7.exe
python-2.7.3.msi
Please help me out with this
November 15, 2012 at 3:49 AM
One thing to check if you're having trouble; make sure the path to the python executable is correct on the shebang line of the hgweb.cgi script
#!C:/python27/python.exe -u
This one got me for longer than necessary.