CentOS 6.3にTrac-0.12.3.ja2をインストール

環境

Pythonバージョン確認

$ paython --version
Python 2.6.6
  • インストールされていない場合は以下でインストールする。
$ sudo yum install -y python

mod_wsgiインストール

$ sudo yum install -y mod_wsgi

SQLiteバージョン確認

$ sqlite3 --version
3.6.20
  • インストールされていない場合は以下でインストールする。
$ sudo yum install -y sqlite python-sqlite

easy_install のインストール

$ sudo yum install -y python-setuptools

yumでインストールされているPythonの確認

$ yum list installed | grep python

Babelをインストール

  • Trac 0.12 以降は ​Babel を利用することでインターフェースの国際化がサポートされる。Trac のインターフェースを日本語化 (国際化) するには Trac より先に Babel をインストールする。
$ sudo easy_install Babel
Searching for Babel
Reading http://pypi.python.org/simple/Babel/
Reading http://babel.edgewall.org/
Reading http://babel.edgewall.org/wiki/Download
Best match: Babel 0.9.6
Downloading http://ftp.edgewall.com/pub/babel/Babel-0.9.6-py2.6.egg
Processing Babel-0.9.6-py2.6.egg
creating /usr/lib/python2.6/site-packages/Babel-0.9.6-py2.6.egg
Extracting Babel-0.9.6-py2.6.egg to /usr/lib/python2.6/site-packages
Adding Babel 0.9.6 to easy-install.pth file
Installing pybabel script to /usr/bin

Installed /usr/lib/python2.6/site-packages/Babel-0.9.6-py2.6.egg
Processing dependencies for Babel
Finished processing dependencies for Babel

Tracインストール

  • Genshiは自動でインストールされる。
$ sudo easy_install http://www.i-act.co.jp/project/products/downloads/Trac-0.12.3.ja2.zip
Downloading http://www.i-act.co.jp/project/products/downloads/Trac-0.12.3.ja2.zip
Processing Trac-0.12.3.ja2.zip
Running Trac-0.12.3.ja2/setup.py -q bdist_egg --dist-dir /tmp/easy_install-eb8hbp/Trac-0.12.3.ja2/egg-dist-tmp-n9rRFL
Genshi is needed by Trac setup, pre-installing
Checking .pth file support in .
/usr/bin/python -E -c pass
Searching for Genshi>=0.6,<0.7dev
Reading http://pypi.python.org/simple/Genshi/
Reading http://genshi.edgewall.org/
Reading http://genshi.edgewall.org/wiki/Download
Best match: Genshi 0.6
Downloading http://ftp.edgewall.com/pub/genshi/Genshi-0.6-py2.6.egg
Processing Genshi-0.6-py2.6.egg
creating /tmp/easy_install-eb8hbp/Trac-0.12.3.ja2/Genshi-0.6-py2.6.egg
Extracting Genshi-0.6-py2.6.egg to /tmp/easy_install-eb8hbp/Trac-0.12.3.ja2

Installed /tmp/easy_install-eb8hbp/Trac-0.12.3.ja2/Genshi-0.6-py2.6.egg
catalog 'trac/locale/vi/LC_MESSAGES/messages.po' is marked as fuzzy, skipping
catalog 'trac/locale/fa/LC_MESSAGES/messages.po' is marked as fuzzy, skipping
catalog 'trac/locale/el/LC_MESSAGES/messages.po' is marked as fuzzy, skipping
Adding Trac 0.12.3.ja2 to easy-install.pth file
Installing trac-admin script to /usr/bin
Installing tracd script to /usr/bin

Installed /usr/lib/python2.6/site-packages/Trac-0.12.3.ja2-py2.6.egg
Processing dependencies for Trac==0.12.3.ja2
Searching for Genshi>=0.6,<0.7dev
Reading http://pypi.python.org/simple/Genshi/
Reading http://genshi.edgewall.org/
Reading http://genshi.edgewall.org/wiki/Download
Best match: Genshi 0.6
Downloading http://ftp.edgewall.com/pub/genshi/Genshi-0.6-py2.6.egg
Processing Genshi-0.6-py2.6.egg
creating /usr/lib/python2.6/site-packages/Genshi-0.6-py2.6.egg
Extracting Genshi-0.6-py2.6.egg to /usr/lib/python2.6/site-packages
Adding Genshi 0.6 to easy-install.pth file

Installed /usr/lib/python2.6/site-packages/Genshi-0.6-py2.6.egg
Finished processing dependencies for Trac==0.12.3.ja2

Tracプロジェクト

$ sudo mkdir /var/trac
  • プロジェクト作成
$ sudo trac-admin /var/trac/[プロジェクト名] initenv
  • プロジェクト作成例
$ sudo trac-admin /var/trac/test_project initenv
新規 Trac Environment /var/trac/test_project の生成

はじめに、プロジェクトのデータベースの初期化と準備をするために、
あなたの環境についていくつか確認をします。

 プロジェクトの名前を入力してください。
 この名前は、ページのタイトルと説明に使用されます。

プロジェクト名 [My Project]> test_project
 
 使用するデータベースへの接続文字列を指定してください。
 デフォルトではローカルに SQLite データベースを作成します。
 既に存在する PostgreSQL データベースを使うこともできます。
 (Trac では、接続文字列は厳密に表記する必要があります。
 詳細は Trac のドキュメントを参照してください)

データベース接続文字列 [sqlite:db/trac.db]> 

プロジェクトの生成と初期化
 デフォルトの Wiki ページのインストール

[中略]

---------------------------------------------------------------------
Trac Environment 'test_project' ができました。

今後、この環境の設定をする場合は、次のファイルを利用します:

  /var/trac/test_project/conf/trac.ini

あなたがこの新しいプロジェクトのテストを考えているなら、
スタンドアロンウェブサーバ `tracd` を試してみてください:

  tracd --port 8000 /var/trac/test_project

それから、ブラウザで http://localhost:8000/test_project にアクセスします。
インストールしたバージョンに合わせた今後のセットアップ情報などが含まれた、
ドキュメントが閲覧できます。(例えばウェブサーバで公開する手順など)

最新のドキュメントは、プロジェクトのウェブサイトから入手できます:

  http://trac.edgewall.org/

Congratulations!
  • 管理者ユーザーを作成
$ sudo trac-admin /var/trac/test_project permission add admin TRAC_ADMIN
  • パスワードファイルを作成
$ sudo htpasswd -c /var/trac/trac.htpasswd admin
  • 入力したパスワードは表示されません。
New password: 
Re-type new password: 
Adding password for user admin
  • デフォルトで登録されている匿名ユーザー権限の確認
$ sudo trac-admin /var/trac/test_project permission list anonymous
ユーザ     アクション     
--------------------------
anonymous  BROWSER_VIEW   
anonymous  CHANGESET_VIEW 
anonymous  FILE_VIEW      
anonymous  LOG_VIEW       
anonymous  MILESTONE_VIEW 
anonymous  REPORT_SQL_VIEW
anonymous  REPORT_VIEW    
anonymous  ROADMAP_VIEW   
anonymous  SEARCH_VIEW    
anonymous  TICKET_VIEW    
anonymous  TIMELINE_VIEW  
anonymous  WIKI_VIEW      


利用できるアクション:
 BROWSER_VIEW, CHANGESET_VIEW, CONFIG_VIEW, EMAIL_VIEW, FILE_VIEW,
 LOG_VIEW, MILESTONE_ADMIN, MILESTONE_CREATE, MILESTONE_DELETE,
 MILESTONE_MODIFY, MILESTONE_VIEW, PERMISSION_ADMIN, PERMISSION_GRANT,
 PERMISSION_REVOKE, REPORT_ADMIN, REPORT_CREATE, REPORT_DELETE,
 REPORT_MODIFY, REPORT_SQL_VIEW, REPORT_VIEW, ROADMAP_ADMIN, ROADMAP_VIEW,
 SEARCH_VIEW, TICKET_ADMIN, TICKET_APPEND, TICKET_CHGPROP, TICKET_CREATE,
 TICKET_EDIT_CC, TICKET_EDIT_COMMENT, TICKET_EDIT_DESCRIPTION,
 TICKET_MODIFY, TICKET_VIEW, TIMELINE_VIEW, TRAC_ADMIN,
 VERSIONCONTROL_ADMIN, WIKI_ADMIN, WIKI_CREATE, WIKI_DELETE, WIKI_MODIFY,
 WIKI_RENAME, WIKI_VIEW
$ sudo trac-admin /var/trac/test_project permission remove anonymous  BROWSER_VIEW 

Trac個別の設定

  • utf8で文字化けする場合
$ sudo vim /var/trac/test_project/conf/trac.ini
[trac]
#default_charset = cp932  #下記に書き換え
default_charset = UTF8

trac.wsgi

$ sudo vim /var/trac/trac.wsgi
import os

os.environ['TRAC_ENV_PARENT_DIR'] = '/var/trac'
os.environ['PYTHON_EGG_CACHE'] = '/var/trac/eggs'

import trac.web.main
application = trac.web.main.dispatch_request
  • 実行権限付与
$ sudo chmod 755 /var/trac/trac.wsgi
  • 所属変更
$ sudo chown -R apache:apache /var/trac/

[Apache]Tracの設定ファイルを作成

$ sudo vim /etc/httpd/vhosts.d/trac.conf
WSGIScriptAlias /trac /var/trac/trac.wsgi

<Directory /var/trac>
    WSGIApplicationGroup %{GLOBAL}
    Order deny,allow
    Allow from all
</Directory>

<LocationMatch "/trac/.*/login">
   AuthType Basic
   AuthName "trac"
   AuthUserFile "/var/trac/trac.htpasswd"
   Require valid-user
</LocationMatch>

Nginxを停止(一時的に)

$ sudo service nginx stop

Apacheを再起動

$ sudo service httpd configtest
$ sudo service httpd restart
  • ブラウザ上で表示できるか確認
http://[サーバーIP]/trac
http://[サーバーIP]/trac/[プロジェクト名]

#例
http://120.0.0.1/trac/test_project


[追記]
Trac-0.12.3.ja2からTrac-1.0.ja1に更新してみる。 - 迷い家の白猫 技術部