Differences between revisions 1 and 19 (spanning 18 versions)
Revision 1 as of 2005-08-28 08:20:13
Size: 2701
Editor: mpm
Comment:
Revision 19 as of 2009-05-19 19:31:03
Size: 3843
Editor: localhost
Comment: converted to 1.6 markup
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
## page was renamed from CGI Install
Line 3: Line 4:
If you would like to publish your repository to the world, it must be made available via a web server. ["Mercurial"] does have a built-in web server which can be used for this, which can be accessed via {{{hg serve}}}. However, it will only allow one connection at a time, and it is not very robust; a broken connection at the wrong time can cause the {{{hg serve}}} to exit. A much better way to do things is to access Mercurial from a CGI script using an Apache web server. If you would like to publish your repository to the world, it must be made available via a web server. [[Mercurial]] does have a built-in web server which can be used for this, which can be accessed via {{{hg serve}}}. However, it will only allow one connection at a time, and it is not very robust; a broken connection at the wrong time can cause the {{{hg serve}}} to exit. A much better way to do things is to access Mercurial from a CGI script using an Apache web server.
Line 5: Line 6:
The following example shows you one way of doing making a repository named {{{repo-name}}} available on the host {{{example.org}}} If you think you may want to serve several repositories from the same server, you should check out HgWebDirStepByStep.
Line 7: Line 8:
== Create a user for the repository. == The following example shows you one way of making a repository named {{{repo-name}}} available on the host {{{example.org}}}.
Line 9: Line 10:
This is not strictly necessary, but it will make it easier to update the repository remotely. == Create a user and setup a repository ==
Line 11: Line 12:
Create a user {{{hg}}} and setup a repository in {{{/home/hg/repo-name}}}:
Line 12: Line 14:
$ adduser hg
$ cd /home/hg
$ mkdir repo-name; cd repo-name
# adduser hg
# su - hg
$ mkdir /home/hg/repo-name; cd /home/hg/repo-name
Line 17: Line 19:
This will create a repository in''home''hg/repo-name. If you create a directory in {{{/home/hg/.ssh}}} and set up its {{{authorized_keys}}} file appropriately, you will be able to remotely update the repository via the command
Line 19: Line 20:
You can add information to the web page about your hg repository by setting following
lines in the config file {{{repo-name/.hg/hgrc}}} are set:
{{{
[web]
description = short description of repo-name
author = Example User <hg@example.com>
}}}

The repository can be remotely updated over ssh. If you want to be able to do this without
explicitly typing a password each time you can create a directory {{{/home/hg/.ssh}}} and set up
its {{{authorized_keys}}} file appropriately (See [[SharedSSH]]). You will be able to remotely
update the repository via the command:
Line 22: Line 35:
== Edit your apache configuration file ==
Line 24: Line 36:
Modifying your apache configuration file is not necessary if you run the the CGI script with a .cgi extension and in a directory that allows CGI execution. In this case, for the step of "Set up {{{index.py}}}", instead of copying hgweb.cgi to index.py, copy it to index.cgi.
Line 26: Line 37:
Place the following in your apache configuration file and reload the apache server so that the configuration changes take effect: == Setup a cgi script to refer to your repository ==
Line 28: Line 39:
{{{
 Alias /hg /home/hg
Most people adding new content to the repository don't need to change the cgi script, so keeping that
separate (maybe even protected by root permissions) is best. Copy the {{{hgweb.cgi}}} script from the
mercurial sources to {{{/var/www/cgi-hg/index.cgi}}} and change the call to {{{hgweb.hgweb()}}} so that the
first argument lists the path to the repository and the second argument gives the name of the repository.
Line 31: Line 44:
 <Directory /home/hg/>
         DirectoryIndex index.py
         AddHandler cgi-script .py
         Options +ExecCGI
 </Directory>
}}}
== Set up index.py ==

Copy hgweb.cgi from the Mercurial source distribution to the root of the repository (i.e., {{{/home/hg/repo-name}}}) as {{{index.py}}} and change the call to hgweb.hgweb() so that the first argument lists the path to the repository and the second argument gives the name of the repository.

Using the example names as used above, the {{{index.py}}} file might look like this:
Using the example names as used above, the {{{index.cgi}}} file might look like this:
Line 45: Line 48:
#
Line 56: Line 58:
Make sure the {{{index.py}}} file is executable: Make sure the {{{index.cgi}}} file is executable:
Line 59: Line 61:
$ chmod a+x index.py $ chmod a+x index.cgi
Line 61: Line 63:


== Edit your apache configuration file ==

Place the following in your apache configuration file and reload the apache server so that the configuration changes take effect:

{{{
Alias /hg /var/www/cgi-hg
<Directory "/var/www/cgi-hg">
    DirectoryIndex index.cgi
    AddHandler cgi-script .cgi
    Options ExecCGI
    Order allow,deny
    Allow from all
</Directory>
}}}

In case you also want to make the repository available as static html files (which should normally
not be necessary), you could add:

{{{
Alias /hg-static /home/hg/repo-name
<Directory "/home/hg/repo-name">
    Options Indexes
    Order allow,deny
    Allow from all
</Directory>
}}}

Line 63: Line 95:
Once you have populated the repository, users will be able to access the repositry using the URL: {{{http://example.org/hg/repo-name}}}. Once you have populated the repository, users will be able to access the repositry using the URL: {{{http://example.org/hg/}}}.


== Multiple repositories ==
<<Anchor(multiple_repos)>>

You'll probably setup several repositories and not only one. The apache configuration can stay the same,
but you then copy the file {{{hgwebdir.cgi}}} to {{{/var/www/cgi-hg/index.cgi}}} and for each repository
the file {{{hgweb.cgi}}} to {{{/var/www/cgi-hg/repo-name/index.cgi}}}.

A better solution is documented in HgWebDirStepByStep.
----
CategoryWeb

Setting up a Mercurial CGI Server

If you would like to publish your repository to the world, it must be made available via a web server. Mercurial does have a built-in web server which can be used for this, which can be accessed via hg serve. However, it will only allow one connection at a time, and it is not very robust; a broken connection at the wrong time can cause the hg serve to exit. A much better way to do things is to access Mercurial from a CGI script using an Apache web server.

If you think you may want to serve several repositories from the same server, you should check out HgWebDirStepByStep.

The following example shows you one way of making a repository named repo-name available on the host example.org.

Create a user and setup a repository

Create a user hg and setup a repository in /home/hg/repo-name:

# adduser hg
# su - hg
$ mkdir /home/hg/repo-name; cd /home/hg/repo-name
$ hg init

You can add information to the web page about your hg repository by setting following lines in the config file repo-name/.hg/hgrc are set:

[web]
description = short description of repo-name
author = Example User <hg@example.com>

The repository can be remotely updated over ssh. If you want to be able to do this without explicitly typing a password each time you can create a directory /home/hg/.ssh and set up its authorized_keys file appropriately (See SharedSSH). You will be able to remotely update the repository via the command:

$ hg push ssh://hg@example.org/repo-name

Setup a cgi script to refer to your repository

Most people adding new content to the repository don't need to change the cgi script, so keeping that separate (maybe even protected by root permissions) is best. Copy the hgweb.cgi script from the mercurial sources to /var/www/cgi-hg/index.cgi and change the call to hgweb.hgweb() so that the first argument lists the path to the repository and the second argument gives the name of the repository.

Using the example names as used above, the index.cgi file might look like this:

import cgitb, os, sys
cgitb.enable()

# sys.path.insert(0, "/path/to/python/lib") # if not a system-wide install
from mercurial import hgweb

h = hgweb.hgweb("/home/hg/repo-name", "name of repository")
h.run()

Make sure the index.cgi file is executable:

$ chmod a+x index.cgi

Edit your apache configuration file

Place the following in your apache configuration file and reload the apache server so that the configuration changes take effect:

Alias /hg /var/www/cgi-hg
<Directory "/var/www/cgi-hg">
    DirectoryIndex index.cgi
    AddHandler cgi-script .cgi
    Options ExecCGI
    Order allow,deny
    Allow from all
</Directory>

In case you also want to make the repository available as static html files (which should normally not be necessary), you could add:

Alias /hg-static /home/hg/repo-name
<Directory "/home/hg/repo-name">
    Options Indexes
    Order allow,deny
    Allow from all
</Directory>

That's it!

Once you have populated the repository, users will be able to access the repositry using the URL: http://example.org/hg/.

Multiple repositories

You'll probably setup several repositories and not only one. The apache configuration can stay the same, but you then copy the file hgwebdir.cgi to /var/www/cgi-hg/index.cgi and for each repository the file hgweb.cgi to /var/www/cgi-hg/repo-name/index.cgi.

A better solution is documented in HgWebDirStepByStep.


CategoryWeb

CGIinstall (last edited 2009-11-30 17:50:03 by PaulBoddie)