Quick and Dirty: A Mercurial Server Under Snow Leopard
June 16, 2010, 4:05 am
Filed under: mac, mercurial, snow leopard, tutorial

This is a fast tutorial to set up, quick and fast, a mercurial server at Snow Leopard using Apache and cgi(the dirty party).

We need:

  1. One apache server, we’ll use the apache shipped with Snow Leopard
  2. Install the mercurial
  3. And the CGI script provide by Mercurial

First, install the mercurial, I used the macports version

sudo port install mercurial

Second, configure the httpd.

Create /etc/apache2/extra/httpd-hg.conf

ScriptAliasMatch        ^/hg(.*)        /var/hg/hgwebdir.cgi$1 #the last one is the the cgi file location
<Directory /var/hg>
AuthType Basic
AuthName "Mercurial repositories"
AuthUserFile /var/hg/.htpasswd # the user file
Require valid-user
Options ExecCGI FollowSymLinks
Order allow,deny
Allow from all
AllowOverride all
AddHandler cgi-script .cgi

Include at /etc/apache2/httpd.conf

Include /etc/apache2/extra/httpd-hg.conf

Third, create the repository, I’m using /var/hg.

sudo mkdir -p /var/hg/repos

Create the cgi configure file hgweb.config at /var/hg

repos/ = repos/
style = gitweb

Download the cgi file from and put at /var/hg

Uncomment the follow lines at hgwebdir.cgi and put the python location:

import sys
sys.path.insert(0, "/System/Library/Frameworks/Python.framework/Versions/2.6/bin")

Create the .htpasswd to authenticate users
htpasswd -c /var/hg/.htpasswd user

At /var/hg/repos, create a repository
hg init /var/hg/repos/<repository-name>

Edit the hgrc under /.hg
push_ssl = false #allow push using non-ssl connection
contact = user
description = teste
allow_push = user user2 #user allowed to push, must exist at .htpasswd

Do not forget to change the permissions at /var/hg to user _www and group _www

sudo chown -R _www:_www  /var/hg

Start the apache server

sudo apachectl -k start

Now you have one repository, you can access using

More info at