This is a fast tutorial to set up, quick and fast, a mercurial server at Snow Leopard using Apache and cgi(the dirty party).
We need:
- One apache server, we’ll use the apache shipped with Snow Leopard
- Install the mercurial
- And the CGI script provide by Mercurial
First, install the mercurial, I used the macports version
sudo port install mercurial
Second, configure the httpd.
Create /etc/apache2/extra/httpd-hg.conf
ScriptAliasMatch ^/hg(.*) /var/hg/hgwebdir.cgi$1 #the last one is the the cgi file location
<Directory /var/hg>
AuthType Basic
AuthName "Mercurial repositories"
AuthUserFile /var/hg/.htpasswd # the user file
Require valid-user
Options ExecCGI FollowSymLinks
Order allow,deny
Allow from all
AllowOverride all
AddHandler cgi-script .cgi
</Directory>
Include at /etc/apache2/httpd.conf
Include /etc/apache2/extra/httpd-hg.conf
Third, create the repository, I’m using /var/hg.
sudo mkdir -p /var/hg/repos
Create the cgi configure file hgweb.config at /var/hg
[collections]
repos/ = repos/
[web]
style = gitweb
Download the cgi file from http://www.selenic.com/repo/hg-stable/raw-file/tip/hgwebdir.cgi and put at /var/hg
Uncomment the follow lines at hgwebdir.cgi and put the python location:
import sys
sys.path.insert(0, "/System/Library/Frameworks/Python.framework/Versions/2.6/bin")
Create the .htpasswd to authenticate users
htpasswd -c /var/hg/.htpasswd user
At /var/hg/repos, create a repository
hg init /var/hg/repos/<repository-name>
Edit the hgrc under /.hg
[web]
push_ssl = false #allow push using non-ssl connection
contact = user
description = teste
allow_push = user user2 #user allowed to push, must exist at .htpasswd
Do not forget to change the permissions at /var/hg to user _www and group _www
sudo chown -R _www:_www /var/hg
Start the apache server
sudo apachectl -k start
Now you have one repository, you can access using http://127.0.0.1/hg/
More info at http://mercurial.selenic.com/wiki/HgWebDirStepByStep
4 Comments so far
Leave a comment
[...] artykuł na: Quick and Dirty: A Mercurial Server Under Snow Leopard « sandbox Tags: basic, file-location, follow, last, options, options-exec, require, the-last, the-the, [...]
Pingback by Quick and Dirty: A Mercurial Server Under Snow Leopard « sandbox - cgi June 16, 2010 @ 6:27 am[...] This is a fast tutorial to set up, quick and fast, a mercurial server at Snow Leopard using Apache and cgi(the dirty party). We need: One apache server, we'll use the apache shipped with Snow Leopard Install the mercurial And the CGI script provide by Mercurial First, install the mercurial, I used the macports version sudo port install mercurial Second, configure the httpd. Create /etc/apache2/extra/httpd-hg.conf ScriptAliasMatch ^/hg(.*) … Read More [...]
Pingback by Quick and Dirty: A Mercurial Server Under Snow Leopard (via sandbox) « Chicago Mac/PC Support June 18, 2010 @ 10:20 pmThanks for posting this. It saved me a *lot* of time! I only had to make two changes:
1) Using hgweb.cgi instead of the suggested download hgwebdir.cgi which is no longer available. As I understand it, hgweb now replaces hgwebdir and was easily found on my own machine as part of the MacPorts installation of Mercurial. I just copied it to the suggested location, and…
2) Replacing the shebang in the hgweb.cgi to be:
!/opt/local/Library/Frameworks/Python.framework/Versions/2.6/Resources/Python.app/Contents/MacOS/Python
which I simply copied out of the hg script itself.
3) And of course the /etc/apache2/extra/httpd-hg.conf has to reflect the name change in to hgweb.cgi
With these minor changes, my own little Mercurial repository came right up.
Thanks again for taking the time to post your recipe!
Comment by Bill Costa November 3, 2011 @ 7:27 pmHello Bill.
Thank you for your report, I’m glad that the text helped and thank you about the updates.
Hélder
Comment by hmbr November 3, 2011 @ 7:48 pm