====== Installing apache + hgweb server locally ======
This post details how to install a hgweb server locally on
an amd64 Debian 12 desktop machine,
as suggested [[blog:pushbx:2025:1022_anonymous_sign_in_now_required_for_the_hgweb_server|in the hgweb sign-in post]].
===== Apache =====
Run the Synaptic Package Manager,
mark apache2, apache2-bin, apache2-data, and apache2-utils for installation.
They are version 2.4.65-1~deb12u1 on our current setup.
Also mark mercurial and mercurial-common for installation.
They are version 6.3.2-1+deb12u1 for us.
Install the marked packages.
===== hgweb =====
According to https://510x.se/notes/posts/Install_Mercurial_and_hgweb_on_a_Debian-based_system/
you can copy the hgweb.cgi file from an installed Mercurial package as follows:
mkdir -p ~/hg/cgi
cp /usr/share/doc/mercurial-common/examples/hgweb.cgi ~/hg/cgi
The contents of this file on our machine are:
#!/usr/bin/env python3
#
# An example hgweb CGI script, edit as necessary
# See also https://mercurial-scm.org/wiki/PublishingRepositories
# Path to repo or hgweb config to serve (see 'hg help hgweb')
config = b"/path/to/repo/or/config"
# Uncomment and adjust if Mercurial is not installed system-wide
# (consult "installed modules" path from 'hg debuginstall'):
# import sys; sys.path.insert(0, "/path/to/python/lib")
# 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)
I edited the ''config ='' line to read ''config = b"/home/ecm/hg/cgi/hgweb.config"''
The hgweb.config file contents are as shown in the following log:
~/hg/cgi$ cat hgweb.config
#[collections]
#/home/ecm/webrepos = /home/ecm/webrepos
[paths]
/ecm = /home/ecm/webrepos/*
[ui]
username = E. C. Masloch
[web]
allow_archive = gz, bz2, zip
encoding = utf-8
[extensions]
highlight =
===== Place the repos =====
Download a .tlz (tar lzipped) file from https://pushbx.org/ecm/backups.hg/ and unpack it:
mkdir webrepos
cd webrepos
tar -xf ~/Downloads/hg/20251019.tlz
===== Install hgweb as part of the apache server =====
1. Run ''chmod a+rx'' on the directories involved in the hgweb.cgi pathname
2. Enable CGI module in apache by running ''/etc/apache2/mods-enabled$ sudo ln -s ../mods-available/cgi.load''
3. Unlike what the 510x.se page states, create a file named ''/etc/apache2/conf-enabled/hg.conf'' (using sudo with a text editor), with the following contents:
ScriptAlias /hg "/home/ecm/hg/cgi/hgweb.cgi"
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Require all granted
4. Run ''sudo service apache2 reload''
5. Navigate to http://127.0.0.1/hg/ecm?sort=lastchange
{{tag>apache hg mercurial hgweb debian}}
~~DISCUSSION~~