Installing Mercurial on Debian 7.5

Mercurial is a software versioning and revision control system to maintain current and historical versions of files such as source code, web pages, and documentation. The development server caters for the hosting of the version control system and also allows for access to it over the HTTPS protocol.

Installing Mercurial

To install Mercurial, we execute the following command in a “root” shell.

apt-get install mercurial mercurial-common

Creating the Mercurial repository

To create the container and set the appropriate ownership and permissions for our Mercurial repositories, we execute the following commands in a “root” shell.

mkdir -p /home/hg
chown www-data:www-data /home/hg
chmod 700 /home/hg

Installing the Apache Module

To enable the submission of files to Mercurial over WebDAV, we install the necessary module by executing the following in a “root” shell.

apt-get install libapache2-mod-wsgi

Configuring Apache

To configure Mercurial, we will host it on a secure virtual host on Apache.

Configuring Apache Module

To configure the module, we will be hosting the files hgweb.config and hgweb.cgi in a directory cgi-bin, which is created by executing the following commands in a “root” shell.

mkdir /home/www-data/sitename
mkdir /home/www-data/sitename/cgi-bin
chown -R www-data:www-data /home/www-data/sitename
chmod -R 770 /home/www-data/sitename

Next, we will create the hgweb.config file, which will contain the following.

[web]
style = monoblue
allow_push = *
push_ssl = true
[paths]
/ = /home/hg/*

Next, we will edit the hgweb.cgi file to contain the following, after copying the example file by executing the following command in a “root” shell.

cp /usr/share/doc/mercurial/examples/hgweb.cgi /home/www-data/sitename/cgi-bin/
#!/usr/bin/env python
#
# An example hgweb CGI script, edit as necessary
# See also http://mercurial.selenic.com/wiki/PublishingRepositories

# Path to repo or hgweb config to serve (see 'hg help hgweb')
config = "/home/www-data/sitename/cgi-bin/hgweb.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)

Finally, we will set the necessary ownership and permissions on the hgweb.config and hgweb.cgi by executing the following commands in a “root” shell.

chown -R www-data:www-data /home/www-data/sitename/cgi-bin
chmod 760 hgweb.cgi
chmod 660 hgweb.config

Virtual Host settings

The virtual host will use the IP address 192.168.100.15, using the certificate in /etc/ssl/CA/certs/sitename.cert and the private key in /etc/ssl/CA/private/sitename.key.nopass. Authentication will also be required using a htpasswd file in /etc/apache2/security/htpasswd.sitename.

To create this htpasswd file, we execute the following command in a “root” shell.

htpasswd -c /etc/apache2/security/htpasswd.sitename admin

We will then be prompted to enter a password for the user admin, and using these credentials we will be able to access the Mercurial web interface.

Virtual Host Configuration

<VirtualHost 192.168.100.15:80>
    RewriteEngine on
    ReWriteCond %{SERVER_PORT} !^443$
    RewriteRule ^/(.*) https://%{HTTP_HOST}/$1 [NC,R,L]
</VirtualHost>

<VirtualHost 192.168.100.15:443>
    ServerName sitename
    ServerAdmin webmaster@domain

    SSLEngine On
    SSLCertificateFile /etc/ssl/CA/certs/sitename.cert
    SSLCertificateKeyFile /etc/ssl/CA/private/sitename.key.nopass

    BrowserMatch "MSIE [2-6]" \
        nokeepalive ssl-unclean-shutdown \
        downgrade-1.0 force-response-1.0
    BrowserMatch "MSIE [17-9]" ssl-unclean-shutdown

    DocumentRoot /home/www-data/sitename
    <Directory /home/www-data/sitename>
        Options SymLinksIfOwnerMatch
        AllowOverride None
        Order allow,deny
        Allow from all
    </Directory>

    Alias /static /usr/share/mercurial/templates/static
    <Directory /usr/share/mercurial/templates/static>
        Options SymLinksIfOwnerMatch
        AllowOverride None
        Order allow,deny
        Allow from all
    </Directory>


    ScriptAlias / /home/www-data/sitename/cgi-bin/hgweb.cgi
    <Location />
        AuthType Basic
        AuthName "Mercurial Repository"
        AuthUserFile /etc/apache2/security/htpasswd.sitename
        Require valid-user
    </Location>

    ErrorLog ${APACHE_LOG_DIR}/sitename/error.log
    CustomLog ${APACHE_LOG_DIR}/sitename/access.log combined
</VirtualHost>

Enabling the Virtual Host

To enable the virtual host, we execute the following command in a “root” shell.

a2ensite sitename

To reload the configuration, we execute the following command in a “root” shell.

service apache2 reload
Advertisements

One thought on “Installing Mercurial on Debian 7.5

Comments are closed.