Setting up hgweb to Serve Multiple Mercurial Repositories

I recently had to set up an Apache server with hgweb to serve multiple mercurial repositories, and thought I’d document the process:

Step 1: Install Apache

$ sudo apt-get install apache2

This installs the apache2 http server. Important locations that have been created are:
/etc/apache2/apache.conf – the apache config file
/var/logs/error.log – the apache server error log

Edit /etc/apache2/apache.conf to set-up your document root. Add the following DocumentRoot directory pretty much anywhere in the file:

#my document root
DocumentRoot /var/www

Note: this step can be skipped if you want to use /var/www, it’s the default location on linux machines.

Step 2: Install Mercurial

If you haven’t already done this:

$ sudo apt-get install mercurial

You’ll also need at least one repository to serve. We’ll make a simple repo in /data/repo

$ cd /data
$ hg init repo

Step 3: Install HgWeb

Get hgweb.cgi from Selenic.com

$ cd /var/www
$ wget http://www.selenic.com/repo/hg-stable/raw-file/tip/hgweb.cgi

Many online sources tell you to get hgwebdir.cgi (including the official mercurial documentation, but this file has been combined with the standard hgweb.cgi, and so no longer exists. Use hgweb.cgi from now on.

Next, add execution permission to the cgi:

$ chmod +x hgweb.cgi

And finally configure apache to execute it. Edit the apache.conf file, adding the following lines:

ScriptAlias /hg /var/www/hgweb.cgi

Configure HgWeb to Serve your Repos

Add a file to /var/www called hgweb.config, containing the following lines:

[paths]
myrepo = /data/repo

The values contained in the paths section are name-value pairs for your repos. You can add more repositories as follows:

[paths]
myrepo = /data/repo
feature_branch_1 = /data/feature1
feature_branch_2 = /data/feature2

Finally, edit hgweb.cgi to point to your hgweb.config. Edit the following line:

config = "/var/www/hgweb.config"

Give your server a quick reboot and you’re set:

$ /etc/init.d/apache2 restart

Sources

It's only fair to share...
Share on FacebookGoogle+Tweet about this on TwitterShare on LinkedIn

Leave a Reply