Phabricatorセットアップした時のメモ

継続的に使うかどうかはこれからですが、コードレビューツールのPhabricatorをセットアップしてみました。
なんでもFacebook内部で使われていたものがオープンソースになったものだとか。
もっともPhabricatorはコードレビューだけじゃなくてバグトラックやレポジトリブラウザなど色々多機能なようです。

goo Wikipediaより

Released in early 2011, Phabricator is an open source collection of web applications 
originally developed at Facebook where it is used there by the engineering team. It 
includes applications for common, collaborative software engineering tasks, such as code 
review, repository viewing, bug and issue tracking, a pastebin, and other applications 
geared toward collaboration of software engineers. It is humorously themed, aiming to 
make tasks like code review be more enjoyable.

本家サイトはこちら
http://phabricator.org/

セットアップ

セットアップの仕方はこちらにあります。
Installation Guide

OSはLinux的なOSなら良し、みたいなことが書いてあります。MacOSXもいけるようですね。試してませんが。
私はXen上のDebian GNU/Linux squeeze で行いました。

まずは依存関係から以下が必要。

あとインストール時にgitが必要でした。

Debianなので全てaptで入れました。

$ sudo aptitude install mysql-server mysql-client 
$ sudo aptitude install libapache2-mod-php5 php5-curl php-apc php5-mysql

それと、ユーザ登録したときなどにメールを送信する必要があり、PHPから直接SMTPサーバに
送信する方法と、ローカルのsendmailコマンドを使う方法があるのですが、私は後者を
設定しました。というかPHPから直接送るのはうまくいきませんでした。私がPHPをよく知らないせいだと思いますが。
なのでsendmailコマンドを入れるためにpostfixをインストール

$ sudo aptitude install postfix

MySQLのセットアップ
といってもPhabricator用のユーザを作るだけですが。

$ mysql -uroot -p
Enter password:(パスワード入力)

GRANT ALL PRIVILEGES ON *.* TO phab@localhost IDENTIFIED BY 'pass' WITH GRANT OPTION;
GRANT ALL PRIVILEGES ON *.* TO phab@"%" IDENTIFIED BY 'pass' WITH GRANT OPTION;


Phabricatorのインストール

私は"/usr/local/phabricator"というディレクトリを切ってそこで作業をしました。

$ sudo mkdir /usr/local/phabricator
$ sudo chown myuser:myuser /usr/local/phabricator
$ cd /usr/local/phabricator
$ git clone git://github.com/facebook/libphutil.git
$ git clone git://github.com/facebook/arcanist.git
$ git clone git://github.com/facebook/phabricator.git
$ cd phabricator
$ git submodule update --init

設定
設定関係はConfiguration Guide

設定ファイルを作ります。

$ cd /usr/local/phabricator/phabricator/conf
$ mkdir custom
$ vi custom/myconfig.conf.php

conf/custom/myconfig.conf.php の内容はこんな感じです。

<?php
return array(

  // Important! This will put Phabricator into setup mode to help you
  // configure things.

  'phabricator.setup' => true,

  // This will be the base domain for your install, and must be configured.
  // Use "https://" if you have SSL. See below for some notes.
  'phabricator.base-uri' => 'http://192.168.0.100/',

  // Connection information for MySQL.
  'mysql.host' => 'localhost',
  'mysql.user' => 'phab',
  'mysql.pass' => 'pass',

  // Basic email domain configuration.
  'metamta.default-address' => 'review@mydomain.co.jp',
  'metamta.domain'          => 'mydomain.co.jp',
  'metamta.mail-adapter' => 'PhabricatorMailImplementationPHPMailerLiteAdapter'

  // NOTE: Check default.conf.php for detailed explanations of all the
  // configuration options, including these.

) + phabricator_read_config_file('production');
?>

ここでは稼働ホストがローカルネットワークの192.168.0.100と仮定しています。

このファイルを設定ファイルとして読み込むように~/.bashrcに保存しておきます。

$ vi ~/.bashrc

export PHABRICATOR_ENV=custom/myconfig

保存して終了。

そしてデータベースの初期化。

$ cd /usr/local/phabricator/phabricator/
$ ./bin/storage upgrade 

Apacheの設定
このホストでは他に用途もないのでApacheはPhabricator専用にしました。

$ sudo vi /etc/apache2/sites-enabled/000-default

こんなかんじで

<VirtualHost *:80>
        ServerAdmin webmaster@localhost

        DocumentRoot /usr/local/phabricator/phabricator/webroot

        RewriteEngine on
        RewriteRule ^/rsrc/(.*)     -                       [L,QSA]
        RewriteRule ^/favicon.ico   -                       [L,QSA]
        RewriteRule ^(.*)$          /index.php?__path__=$1  [B,L,QSA]

        SetEnv PHABRICATOR_ENV custom/myconfig

        ......

あとはrewriteが使えるようにしておきます。

$ sudo a2enmod rewrite

ここまでやったらApache再起動。

$ sudo /etc/init.d/apache2 restart

で、この場合は http://192.168.0.100 にブラウザでアクセスすると各種設定が実行されるはず。
多分途中でFailureが出ていろいろ言われるのでその都度修正をかけます。

いろいろ修正をかけて、完了のメッセージが出たら先ほどの設定ファイルから"'phabricator.setup' => true"の行をコメントアウトします。
conf/custom/myconfig.conf.php

<?php
return array(

  // Important! This will put Phabricator into setup mode to help you
  // configure things.

  //'phabricator.setup' => true, <=コメントアウト

   ....

それから最初のユーザを作ります。2人目からはWeb画面上で作れます。

$ cd /usr/local/phabricator/phabricator/
$ ./bin/accountadmin


そして再び http://192.168.0.100 にアクセスするとトップ画面が表示されるはず。