Ubuntu 10.4 and Mercurial-Server (Apache2, mod_wsgi)

You know, when you start coding you always (don’t you?) end up looking for a safe-and-easy way to track code changes, code commit log and manage the “back-to-the-past” feature (for example when you start coding a new feature and end up in a completely not working app) πŸ™‚

Sometimes I used free services for repositories (like GitHub, BitBucket, SourceForge) to store my open-source projects (BitBucket plans allow you also to setup a single private repository with 1Gb of free space).

Now I’m setting up something like that for my Lab, allowing students to work from home and share their code with co-workers and professors. I’m happy with Mercurial, so I’ve installed on our web-server (latest Ubuntu Server) all the stuff for serving mercurial repositories with SSH authentication.

Here is my recipe for: SSH push/pull management of repository and a web-page for repository overview. I’ve used mercurial-server tool and configured Apache2 with mod_wsgi for Python.


Following Ekkes tutorial let’s setup the mercurial-server in Ubuntu, we don’t have any X server, so everything is done in a shell:

$ sudo apt-get install mercurial-server

All our repo will be stored in “/etc/lib/mercurial-server/repos” and a special repository called “hgadmin” have been created to manage users and permissions, read on Mercurial-Server docbook for further details. In short: adding myself to “root” group and refreshing users permissions in mercurial-server:

$ sudo mkdir /etc/mercurial-server/keys/root/thepanz
$ sudo cp my_ssh_key.pub /etc/mercurial-server/keys/root/thepanz
$ sudo -u hg /usr/share/mercurial-server/refresh-auth

Mod_wsgi install

For repository serving I’ll use Apache and mod_wsgi, I’ve adapted what presented on mercurial-server blog post and what I’ve found on Mercurial documentation on modwsgi. I’m going to install the latest mod_wsgi release, the 3.3 version, instead of the (1year old) 2.8 that’s packaged into Ubuntu 10.4, I’m going to use the 3.3 release provided from Debian Packages for wsgi mod. Please follow the download page to obtain the correct download link. In the following we’ll first install the Ubuntu mod_wsgi package and then upgrade with the newest one.

$ sudo apt-get install libapache2-mod-wsgi
$ sudo dpkg -i libapache2-mod-wsgi_3.3-1_i386.deb

Apache Serving

Apache will be set to serve the repository using a VirtualHost listening to the 8080 port, here is the “/etc/apache2/sites-available/hgwebsite” file:

<VirtualHost *:8080>
  ServerAdmin webmaster@localhost
  # ServerName hg.exampleserver.net
  DocumentRoot /var/www/sites/hg
  LogLevel warn
  ErrorLog /var/log/apache2/error-sites-hg.log
  CustomLog /var/log/apache2/access-sites-hg.log combined
  WSGIScriptAliasMatch ^(.*)$ /var/www/sites/hg/cgi-bin/hgweb.wsgi$1
  <Directory /var/www/sites/hg>
    DirectoryIndex index.html
    Options Indexes FollowSymLinks MultiViews
    AllowOverride All
    Order allow,deny
    Allow from all
  <Directory /var/www/sites/hg/cgi-bin>
    Options ExecCGI FollowSymlinks
    AddHandler wsgi-script .wsgi
    AllowOverride None
    Order allow,deny
    Allow from all

As attachment you’ll find the scripts for the server setup:

  • hgweb.wsgi to be placed in “/var/www/sites/hg/cgi-bin/” with the Python script for repository serving
  • hgweb.confΒ  to be placed in “/var/lib/mercurial-server/” containing the repositories configuration

That’s it!

2 thoughts on “Ubuntu 10.4 and Mercurial-Server (Apache2, mod_wsgi)

  1. Good Work.
    I am finding this for last 4 days.
    Thanks you very much.

Comments are closed.