Furor Teutonicus blog | over | volg | teuto | lyme | archief | doneer | todo
🕰️
  ⬩  
✍️ Evert Mouw
  ⬩  
⏱️ 2 min

Install Mercurial WSGI on Scientific Linux 6.5

Introduction

Hg logo

Programmers, writers and other creative persons use source code version control systems to keep track of changes, histories and milestones of their work. They also use such systems to work together in teams. The Mercurial (Hg) system is especially popular with Python programmers. A good introduction can be fout at Hg Init.

This guide shows how to install a web-based Hg (Mercurial hgweb) repository on your Apache webserver that runs soms version of Enterprise Linux 6, e.g. Red Hat Enterprise Linux (RHEL), CentOS, or Scientific Linux. It will use the fast WSGI method instead of CGI. This guide was tested with Scientific Linux 6.5.

I must attribute much gratitude to an earlier guide written by Josip Medved (Medo) titled Mercurial on CentOS 6.2. You might still want to read that guide too; it is somewhat more verbose.

Furthermore, I have used the fine documentation from Mercurial itself, located at: http://mercurial.selenic.com/wiki/modwsgi

Install Mercurial

I assume you already have installed Apache and Python on your server.

yum install mercurial

Create directories and files

Create directories

mkdir -p /srv/hg/repos
mkdir -p /srv/hg/cgi-bin

Create /srv/hg/cgi-bin/hgweb.wsgi

# An example WSGI for use with mod_wsgi, edit as necessary
# See http://mercurial.selenic.com/wiki/modwsgi for more information
#
# Path to repo or hgweb config to serve (see 'hg help hgweb')
config = "/srv/hg/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()
#
# enable demandloading to reduce startup time
from mercurial import demandimport; demandimport.enable()
#
from mercurial.hgweb.hgwebdir_mod import hgwebdir
application = hgwebdir(config)

Create /srv/hg/cgi-bin/hgweb.config

[web]
# Themes: see http://mercurial.selenic.com/wiki/AvailableThemes
# bundles themes include {paper, coal, gitweb}
style = paper
allow_push = *
push_ssl = false
#
[paths]
/ = /srv/hg/repos/**

Create a test repository

cd /srv/hg/repos
hg init test

Apache configuration

I assume you use vhost.d virtual domains. If you don’t, you might consider creating /etc/httpd/conf.d/vhost.conf

# added to activate the non-RHEL-standard vhost.d directory
Include vhost.d/*

Add to /etc/httpd/vhost.d/your-domain-name

# Mercurial (Hg) version control system, using WSGI
WSGIScriptAlias /hg "/srv/hg/cgi-bin/hgweb.wsgi"
<Location /hg>
    AuthType Basic
    AuthName "mercurial"
    AuthUserFile  /srv/hg/repos/.htpasswd
    Require valid-user
</Location>
# The "Directory" blocks seems unneccesarry but YMMV
#<Directory /srv/hg/repos>
#   Options FollowSymlinks
#   DirectoryIndex index.html
#   AllowOverride None
#   Order allow,deny
#   Allow from all
#</Directory>
#<Directory /srv/hg/cgi-bin>
#   Options ExecCGI FollowSymlinks
#   AddHandler wsgi-script .wsgi
#   AllowOverride None
#   Order allow,deny
#   Allow from all
#</Directory>

Create users and passwords

touch /srv/hg/repos/.htpasswd
htpasswd /srv/hg/repos/.htpasswd testuser

(You could also use the htpasswd -c option, but be careful — it destoys an existing file, including all earlier created users.)

Set ownership of files and SELinux labels

chown -R apache:apache /srv/hg
chcon -t httpd_sys_content_t -R /srv/hg

Restart Apache

service httpd restart

Finally

It should work now. Test it using your browser.

firefox http://your-domain-name/hg

Remember: When creating new repositories, you must make apache the owner of the files. Also, make sure SELinux labels are right usingls -alZ or repeat the chcon command from above.

If you like Markdown, then you should consider the Markdown Extension for hgweb as well.

Happy hacking!


Deze blogpost werd in december 2022 overgezet van WordPress naar een methode gebaseerd op Markdown; het is mogelijk dat hierbij fouten of wijzigingen zijn ontstaan t.o.v. de originele blogpost.