【HG】 Mercurial ~環境構築編~

  ■ 設定環境

 * OS          : CentOS 7.2.1511
 * HTTP Server : Apache HTTP Server 2.4.6
 * Mercurial   : Mercurial 2.6.2

 

  ■ 設定方法

 * 今回は、yum でインストールする
 * Apacheの連携する際は、事前にApacheをインストールしておくこと
  (以下の関連記事を参照のこと)
http://blogs.yahoo.co.jp/dk521123/36300671.html

  【構成】

 * 以下の構成で構築する

usr/local
 + hg
   + config ... 設定ファイル
   |
   + htdocs ... ディレクトリ(この配下にリポジトリを管理)
   |
   + cgi-bin ... ディレクトリ
       + hgweb.wsgi ... Web公開用のスクリプト

  手順

[1] 上記【構成】のもととなるディレクトリを作成しておく

sudo mkdir /usr/local/hg
sudo mkdir /usr/local/hg/htdocs
sudo mkdir /usr/local/hg/cgi-bin

[2] yumで、mercurialをインストールする

# yum でインストール
sudo yum install mercurial
# 確認
hg --version

[3] Web公開用のスクリプトを上記【構成】のようになるように配置する

sudo cp /usr/share/doc/mercurial-2.6.2/hgweb.wsgi /usr/local/hg/cgi-bin/hgweb.wsgi

[4] Web公開用のスクリプトを以下のように修正する

sudo vi /usr/local/hg/cgi-bin/hgweb.wsgi

【修正前】config = "/path/to/repo/or/config"
【修正後】config = "/usr/local/hg/config"

[5] usr/local/hg/configを作成する

sudo vi /usr/local/hg/config

=> 以下の【ファイル内容 : /usr/local/hg/config】を参照
【ファイル内容 : /usr/local/hg/config】
[web]
style=coal
allow_push=*
push_ssl=false
allow_archive=zip,gz,bz2
encoding=utf-8
prefix=/hg
[paths]
/=/usr/local/hg/htdocs/*

  Apacheとの連携

[1] SELinuxをpermissiveモードにし、一旦、OSを再起動

 * エディタで /etc/sysconfig/selinux を開き、 SELINUX= の値を permissive に変更

sudo vi /etc/sysconfig/selinux
~~~~
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
SELINUX=permissive
~~~~
reboot

[2] mod_wsgi をインストールしておく

# mod_wsgi(Pythonapache上で動作させる為のモジュール)をインストール
sudo yum -y install mod_wsgi

[3] ディレクトリ hg をapacheに変更する

# chownの-Rオプションで指定ディレクトリ配下の所有者をapache:apacheに変更
sudo chown -R apache:apache /usr/local/hg

[4] Apache - Mercurial との間の設定ファイルを追加する

sudo vi /etc/httpd/conf.d/hg.conf

=> 以下の【ファイル内容 : /etc/httpd/conf.d/hg.conf】を参照

[5] 設定ファイルの文法チェックし、問題なければ、Apacheを再起動する

# 文法チェック(「Syntax OK」が表示されたらOK)
apachectl configtest

# 再起動
systemctl restart httpd.service

[6] ブラウザを開き、『http://【(localhostなど)】/hg』でアクセスして、
    Title「Mercurial repositories index」が表示されたらOK

なお、エラー「403 Forbidden」が表示された場合、以下の関連記事を参照のこと
http://blogs.yahoo.co.jp/dk521123/36335847.html

 

【ファイル内容 : /etc/httpd/conf.d/hg.conf】
<IfModule mod_wsgi.c>
  AddHandler wsgi-script .wsgi
  WSGIScriptAlias /hg /usr/local/hg/cgi-bin/hgweb.wsgi

  <Directory "/usr/local/hg/cgi-bin">
   Options ExecCGI FollowSymLinks

   AllowOverride None
   Require all granted
  </Directory>

  <Directory "/usr/local/hg/htdocs">
   Options FollowSymLinks

   AllowOverride None
   Require all granted
  </Directory>
</IfModule>