Differences between revisions 11 and 84 (spanning 73 versions)
Revision 11 as of 2007-04-03 22:07:38
Size: 6516
Editor: ScottFerris
Comment:
Revision 84 as of 2013-09-01 10:59:38
Size: 292
Editor: PCOVerena
Comment:
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
[[TableOfContents]]
= Publishing Repositories with hgwebdir.cgi =

== Introduction ==

Well, we have a certain setup with subversion. I'd like to reproduce it using Mercurial.

== Pre-requisites ==

The installed software is:
 * A webserver that can run CGI scripts such as apache2 (apache2, apache2-common, apache2-mpm-prefork, apache2-utils) or lighttpd
  * But it is not necessary (see below)
 * some version of mercurial (mine was 0.9 taken from Debian/unstable)
 * python:
   * Ubuntu/Edgy comes with python 2.4
   * you will need python2.4-dev package as well
 * sudo (in general, I prefer sudo to su)

== Getting proper Mercurial ==

The whole point was to try pull/push over http. So the following was done (I'm
a real newbie for hg, so please bear with me :)):
{{{
$ cd working-directory
$ hg clone http://selenic.com/hg/
$ cd hg
$ python setup.py build
$ sudo python setup.py install
}}}

== Directory Structure ==

Create the necessary directories:
{{{
$ sudo mkdir -p /var/hg/repos
$ sudo chown -R www-data:www-data /var/hg
}}}

It's usually a good idea to keep special directories out of the tree served by apache.

== Preparing the config ==

{{{
$ cat > /tmp/hgweb.config
[collections]
repos/ = repos/
^D
$ sudo -u www-data cp /tmp/hgweb.config /var/hg
$ rm /tmp/hgweb.config
}}}


== Two possibilities ==
You can either use a separate webserver such as Apache or lighttpd, or use the webserver built into hg.

=== Using Apache or lighttpd with the hgwebdir.cgi script ===

==== Putting the right stuff in place ====

Put the script in place (remember, we are still in that `working-directory/hg` :)):
{{{
$ sudo -u www-data cp hgwebdir.cgi /var/hg
$ sudo -u www-data chmod +x /var/hg/hgwebdir.cgi
}}}

==== Configuring apache ====

Ok, now it's time for apache.

First of all, do not really change the config of apache directly:
{{{
$ sudo mkdir /etc/apache2/hg
}}}

Create the config with the following contents (e.g by using `sudo vim /etc/apache2/hg/main.conf`):
{{{
ScriptAliasMatch ^/hg(.*) /var/hg/hgwebdir.cgi$1

<Directory /var/hg>
  Options ExecCGI FollowSymLinks

  AllowOverride None
</Directory>
}}}

This config says that we are going to serve our repositories through '<yourhost>/hg/'.

Now make it really available, by changing your favourite site in `/etc/apache2/sites-enabled`.
For this experiment I used `/etc/apache2/sites-enabled/default`:
{{{
  ...
  Include /etc/apache2/hg/main.conf
</VirtualHost>
}}}

Make sure that everything is OK:
{{{
$ sudo apache2ctl configtest
Syntax is OK
}}}

Restart your web server:
{{{
$ sudo apache2ctl stop
$ sudo apache2ctl start
}}}

Check if it works by directing your browser to `<yourhost>/hg/`

==== Configuring lighttpd ====

Ok, now it's time for lighttpd.

You can either update the existing /etc/lighttpd/lighttpd.conf file, or create /etc/lighttpd.conf/hg.conf and include that file from lighttpd.conf.

First, you need to check if mod_rewrite and mod_cgi are enabled in the config file, and add them to server.modules if they haven't already been added:
{{{
server.modules += ( "mod_cgi" )
server.modules += ( "mod_rewrite" )
}}}

Next, configure rewrite rules that map URLs to the hgwebdir.cgi script.
With the following added to your config file, URLs starting with either hg or mercurial will map to hgwebdir.cgi:
{{{
url.rewrite-once = (
  "^/hg([/?].*)?$" => "/hgwebdir.cgi$1",
   "^/mercurial([/?].*)?$" => "/hgwebdir.cgi$1"
)
}}}

Then, configure a URL match that invokes hgwebdir.cgi:
{{{
$HTTP["url"] =~ "^/hgwebdir.cgi([/?].*)?$" {
      server.document-root = "/var/hg/"
      cgi.assign = ( ".cgi" => "/usr/bin/python" )
}
}}}

Make sure that everything is OK:
{{{
$ sudo lighttpd -t -f /etc/lighttpd/lighttpd.conf
Syntax OK
}}}

Restart the web server:
{{{
$ sudo /etc/init.d/lighttpd restart
}}}

Check if it works by directing your browser to `<yourhost>/hg/` or `<yourhost>/mercurial/`

=== Standalone ===

Simply run
{{{
sudo -u www-data hg serve --webdir-conf /var/hg/hgweb.config
}}}
and enjoy this speedy method of serving multiple repos. It should be faster than using Apache.

== You are done ==

Hooray!

== Final Bits ==

=== Create a new repository ===

{{{
$ sudo -u www-data hg init /var/hg/repos/<repository-name>
}}}

=== Provide more information about it ===

Add the following to the `/var/hg/repos/<repository-name>/.hg/hgrc` file:
{{{
[web]
contact = Bilbo Baggins # Whom to contact, plain text,
                              # no fancy stuff
description = My precious! # Nice description what this is about,
                              # you can include HTML (like <a>)
}}}

=== Allow pushing to the repository ===

By default, nobody is allowed pushing.

To allow pushing to everybody, add the following line to the `/var/hg/repos/<repository-name>/.hg/hgrc` file:
{{{
[web]
allow_push = *
}}}

To allow only selected users to push changes, add the following line to the `/var/hg/repos/<repository-name>/.hg/hgrc` file:
{{{
[web]
allow_push = frodo, sam
}}}

These are virtual users (for instance, as defined using a .htpasswd file), and not real system users.

=== Deny pushing to the repository ===

Most likely you will want to use it together with `allow_push = *`. If you want allow pushing to everybody, but a selected list of people, add the following line to the `/var/hg/repos/<repository-name>/.hg/hgrc` file:
{{{
[web]
deny_push = saruman
}}}

=== Allow pushing only over a non-secure channel ===

(I still need to check how it works :) )

By default, pushes are allowed only over https. If you are certain and do not want to enforce https for pushes, add the following line to the `/var/hg/repos/<repository-name>/.hg/hgrc` file:
{{{
[web]
push_ssl = false
}}}

=== Customize the look ===

Add the following to the `/var/hg/repos/<repository-name>/.hg/hgrc` file:
{{{
[web]
style = gitweb # looks cleaner from my point of
                            # view :)
allow_archive = gz zip bz2 # If you think people should be able
                            # to download snapshots as .tar.gz,
                            # .zip, .tar.bz2 respectively
}}}

== Disclaimer ==

Well, it works (worked) for me. Please do not hesitate to update this page to
include small bits I've forgotten or just plainly am not aware of.
Electrical Engineer Landon Rozema from Balcarres, really loves pets, facebook and autographs. Was exceptionally encouraged after visiting [[http://www.merriam-webster.com/dictionary/defensive|Defensive]] Wall of Bellinzona. [[http://howtounlockipad3.com/?p=107|search engine optimization]]

Electrical Engineer Landon Rozema from Balcarres, really loves pets, facebook and autographs. Was exceptionally encouraged after visiting Defensive Wall of Bellinzona. search engine optimization

HgWebDirStepByStep (last edited 2018-11-26 18:38:58 by JordiGH)