2008年8月22日

Installing trac on OSX



Installing trac on OSX with mysql db.


MacOSX 10.5.4 Leopard with MacPorts


◎ 安裝 trac
 
sudo port install trac +mysql


+mysql 表示可以原 sqlite 改用 mysql.


◎ 安裝資料庫 參考 http://trac.edgewall.org/wiki/MySqlDb 建立 DB
 
CREATE DATABASE trac_projects DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;
CREATE USER tracuser IDENTIFIED BY 'password';
GRANT ALL ON trac_projects.* TO tracuser;


◎ 啟始某目錄做為放置 Trac 的目錄
 
trac-admin /Users/derjohng/TracDBs/Projects/ initenv


四個步驟
 
Project Name [My Project]> Projects
Database connection string [sqlite:db/trac.db]> mysql://tracuser:password@localhost/trac_projects
Repository type [svn]>
Path to repository [/path/to/repos]> /Users/derjohng/SVN_repo/Projects


◎ 可能出現下述錯誤訊息
 
LookupError: unknown encoding: X-MAC-TRAD-CHINESE


這是 python encoding 的問題,找出


/opt/local/lib/python2.5/site-packages/trac/admin/console.py line:119



 
encoding = locale.getpreferredencoding() # sys.argv


換成
 
encoding = 'utf-8'


◎ 設定 httpd.conf


裝完 mod_python
 
sudo port install mod_python25


然後此行加到 httpd.conf
 
LoadModule python_module modules/mod_python.so


為每個 Trac DB 設定如下
 
Alias /trac/Projects/ "/Users/derjohng/TracDBs/Projects/"
<Directory "/Users/derjohng/TracDBs/Projects/">
AllowOverride None
Options None
Order allow,deny
Allow from all
SetHandler mod_python
PythonHandler trac.web.modpython_frontend
PythonOption TracEnv "/Users/derjohng/TracDBs/Projects/"
PythonOption TracUriRoot "/trac/Projects"
</Directory>


可能有下述錯誤
 
[error] make_obcallback: could not import mod_python.apache.
ImportError: No module named mod_python.apache


這是 mod_python 要找 python 路徑出問題,可以檢查是否 python 能用到 MacOSX 舊的,而非 MacPorts 版


看一下 ls /usr/bin/py* 是不是非 MacPorts 的 python 程式仍存在,若是全清掉


再重建 mod_python2.5 之後就可以了


◎ 網頁也可能出現下述錯誤的訊息
 
LookupError: unknown encoding: X-MAC-TRAD-CHINESE


找出 /opt/local/lib/python2.5/site-packages/trac/util/datefmt.py line:111 的
 
encoding = locale.getlocale(locale.LC_TIME)[1] or encoding


改成
 
encoding = 'utf-8'


應該 locale.LC_TIME=X-MAC-TRAD-CHINESE 的緣故


◎ Trac 的 login 機制,是藉由 Apache Authentication 來進行,apache 設定如下:
 
<Location /trac/Projects/login>
AuthType Basic
AuthName "MyProjects"
AuthUserFile /Users/derjohng/TracDBs/htpasswd_file
Require valid-user
</Location>


◎ Trac 預設只有匿名旳權限,要用 trac-admin 給予其他使用者的權限,比如
 
trac-admin /Users/derjohng/TracDBs/Projects/ permission add admin TRAC_ADMIN


即給 admin 有 TRAC_ADMIN 權限。


◎  Browser Source 的網頁瀏覽原本 UTF-8 文字,會變亂碼,找出 TracDBs/Projects/conf/trac.ini 內
 
default_charset = iso-8859-15


改成
 
default_charset = utf-8


即可




Orignal From: Installing trac on OSX