I got a couple of queries recently on how to make your mercurial-server repositories publically readable over HTTP. Happily this isn’t hard to do, and doesn’t really touch on mercurial-server itself. Here’s how we do it on our Debian systems; in what follows I assume that you have installed mercurial-server on hg.example.com, and that you’re not already using that machine as a web server for anything else. First install these packages; note that they tend to have a lot of stuff you don’t need marked as recommended, so don’t install those things:
apt-get --no-install-recommends install apache2 libapache2-mod-fcgid python-flup
Create the following four files:
[collections] /var/lib/mercurial-server/repos = /var/lib/mercurial-server/repos
[web] style = gitweb allow_archive = bz2 gz zip baseurl = http://hg.example.com/ maxchanges = 200
#!/usr/bin/env python from mercurial import demandimport; demandimport.enable() import os os.environ["HGENCODING"] = "UTF-8" os.environ["HGRCPATH"] = "/etc/mercurial-server/hgweb.hgrc" from mercurial.hgweb.hgwebdir_mod import hgwebdir from mercurial.hgweb.request import wsgiapplication from flup.server.fcgi import WSGIServer def make_web_app(): return hgwebdir("/etc/mercurial-server/hgweb.config") WSGIServer(wsgiapplication(make_web_app)).run()
<VirtualHost *> ServerName hg.example.com AddHandler fcgid-script .fcgi ScriptAlias / /etc/mercurial-server/hgwebdir.fcgi/ ErrorLog /var/log/apache2/hg/error.log LogLevel warn CustomLog /var/log/apache2/hg/access.log combined </VirtualHost>
Finally run these commands as root:
chmod +x /etc/mercurial-server/hgwebdir.fcgi mkdir -p /var/log/apache2/hg cd /etc/apache2/sites-enabled rm 000-default ln -s ../sites-available/hg /etc/init.d/apache2 reload
Your files should now be served at http://hg.example.com/ . Sadly because of a design flaw in hgwebdir, there’s no easy way to get Apache to handle the static files it needs, but these are pretty small so there’s no harm in letting hgwebdir handle them. The “rm 000-default” thing seems pretty undesirable, but without it I can’t seem to get this recipe to work.
I’ve chosen FastCGI as the connector. This has the advantage that
- unlike CGI, it doesn’t fork a new handler on every request
- unlike mod_python, it keeps your Mercurial handler separate from your web server
- unlike SCGI, it will automatically start the service for you if it’s not already running, which is a massive convenience
I’m not aware of any other way of working that offers all three advantages.