はじめに
Tracの環境を構築する際に色々とハマったのでメモとして残しておきます。
実行環境
- CentOS Linux release 7.5.1804 (Core)
Tracのインストール
yum install subversion-python
今回はTracを使ってSubversionを管理するのでインストールします。
これがないとTrac上でSubversionの管理ができないようです。
easy_install Babel
easy_install Trac
Tracを日本語化するためにBabelが必要なようです。
インストールする順番もBabel→Tracにする必要あり。
※きちんと調べていないので正しい情報ではないかもしれません。
プロジェクト環境の作成
trac-admin /path/to/MyProject initenv
プロジェクト名とデータベース接続文字列を入力する。
今回はデータベース接続文字列を特に指定しませんでした。
今回は自分自身のユーザアカウントに管理者権限を持たせます。
trac-admin /path/to/MyProject permission add MyUser TRAC_ADMIN
ダイジェスト認証用パスワードファイルの生成
htdigest -c /path/to/htpasswd trac MyUser
htdigest /path/to/htpasswd trac NextUser
Tracのデプロイ
スタンドアローンサーバーの実行
tracd --port 80 --base-path trac --protocol=http --auth="*,/path/to/htpasswd,trac" MyProject/
80番ポートでサブディレクトリに/tracを指定しています。
WEBサーバーでのTracの実行
Tracのcgi-binディレクトリの生成
trac-admin /path/to/MyProject deploy /path/to/MyProject/dist
chmod 777 /path/to/MyProject/dist/cgi-bin/trac.fcgi
MyProjectフォルダの中にdistフォルダを作ってcgi-binディレクトリを生成しています。
cgiファイルに実行権限をつけておきます。
chown -R apache:apache /path/to/MyProject
MyProject以下のファイルの所有者をapacheユーザに変更します。
変更しないと書き込み権限がなくエラーになってしまうようです。
FastCGIの導入
ライブラリのインストール
yum install httpd-devel gcc
cd /usr/local/src/
wget https://www-eu.apache.org/dist//httpd/mod_fcgid/mod_fcgid-2.3.9.tar.gz
tar zxvf mod_fcgid-2.3.9.tar.gz
cd mod_fcgid-2.3.9/
./configure.apxs
make
make install
Trac用にApacheの設定ファイルを作成
httpd -v
Server version: Apache/2.4.6 (CentOS)
Server built: Jun 27 2018 13:48:59
<Directory /path/to/MyProject/dist/cgi-bin/>
SetHandler fcgid-script
Options +ExecCGI
# Customize the next two directives for your requirements.
AllowOverride All
Require all granted
</Directory>
ScriptAlias /trac /path/to/MyProject/dist/cgi-bin/trac.fcgi/
DefaultInitEnv TRAC_ENV /path/to/MyProject/
<Location "/trac">
AuthType Digest
AuthName "trac"
AuthDigestDomain /trac
AuthUserFile /path/to/htpasswd
Require valid-user
</Location>
サブディレクトリに/tracを設定しています。
/tracにアクセスに来たときダイジェスト認証を行います。
以上でTracを利用できるようになっているはず。
TracでSubversionリポジトリ管理
うまく設定できていればブラウザの管理コンソールからリポジトリの設定ができるはず。
コマンドラインでのリポジトリ管理も記載します。
# 管理中のリポジトリ一覧を表示します
trac-admin /path/to/MyProject/ repository list
# Tracプロジェクトに管理リポジトリを追加します
trac-admin /path/to/MyProject/ repository add MyProject /path/to/SvnRepos/Project/
chmod +x /path/to/SvnRepos/Project/hooks/post-commit
vim /path/to/SvnRepos/Project/hooks/post-commit
フックスクリプトに実行権限がないと失敗するので注意
Tracがsvnのコミットを検知する用にフックスクリプトを作成
# !/bin/sh
REPOS="$1"
REV="$2"
trac-admin /path/to/MyProject/ changeset added "$REPOS" "$REV"
おまけ
今回はNginxをプロキシサーバーとして動かしています。
TracをApacheの設定で50080番ポートで実行しています。
Nginx:80->Apache:50080->Tracとなっています。
Nginxの設定ファイルもおまけで記載します。
server {
listen 80;
server_name localhost;
access_log /var/log/nginx/trac.access.log main;
error_log /var/log/nginx/trac.error.log info;
location /trac {
proxy_pass http://localhost:50080/trac;
}
}