之前一直在使用Mercurial,但还没有亲自搭建过通过HTTP访问的Mercurial Reposities。
今天练习了一回,把过程记录下来备查。(非常简单)
============================================================
前提
Mecurial已经安装完成,并且所有hg repository都在目录/home/twer/hg-repo之下,
比如/home/twer/hg-repo/myproject是我自己的项目repository.
--安装apache2
1. 'sudo apt-get install apache2'
2. when visit http://[IP-of-the-box], then 'It works' shows up.
--Expose hg repository by apache2
1. download hgwebdir.cgi to /var/www
2. 'chmod u+x /var/www/hgwebdir.cgi'
3. 'chown -R www-data:www-data /var/www'
4. 在/var/www目录下创建文件:hgweb.config,内容如下:
[collections]
/home/twer/hg-repo = /home/twer/hg-repo
5. 编辑文件 /apache2/sites-enabled/000-default
在<Directory /var/www>之前加入一行 ScriptAlias /hg "/var/www/hgwebdir.cgi"
6. 重启apache(使用命令: sudo /etc/init.d/apache2 restart)
-- 此时,你可以通过 http://[IP-of-the-box]/hg查看所有的repository。
=============================================
-- 使用Basic Auth才能访问Repository
1. 生成密码文件. 用户名为jez
run command 'htpasswd -c /home/twer/hg-repo/password.properties jez
在提示符后输入你的密码。
2. 编辑文件 /etc/apache2/sites-enable/000-default,在<Directory /var/www> section之后加入下面的section(这两个节点是并列的)
<Location /hg>
AuthType Basic
AuthName "Mercurial repositories"
AuthUserFile /home/twer/hg-repo/password.properties
Require valid-user
</Location>
3. 重启apache2 'sudo /etc/init.d/apache2 restart'
4. 当访问 http://[IP-of-the-box]/hg时,会提示输入用户名和密码。
=============================================
--使用用户名和密码才能进行push
1. 配置hg,使所有人都可以push
在linux用户www-data的home目录中建立文件.hgrc,其内容如下
[web]
allow_push = *
push_ssl = false
2. 让apache2对hg repository有写权限
sudo chown -R www-data:www-data /home/twer/hg-repo
3. 需要用户名和密码才能push
将文件/etc/apache2/sites-enable/000-default中的如下片段
<Location /hg>
AuthType Basic
AuthName "Mercurial repositories"
AuthUserFile /home/twer/hg-repo/password.properties
Require valid-user
</Location>
改为
<Location /hg>
AuthType Basic
AuthName "Mercurial repositories"
AuthUserFile /home/twer/hg-repo/password.properties
<LimitExcept GET>
Require valid-user
</LimitExcept>
</Location>
4. 重启apache2 'sudo /etc/init.d/apache2 restart'
完毕。使用命令 ‘hg clone http://[IP-of-the-box]/hg/myproject’试一下吧。