Snow LeopardにRedmineを導入

とまぁ、自分のMac上で開発するわけなので、バージョン管理とかプロジェクト管理ツールなんかをインストールすることにした。

参考にしたのはコチラ。

■追記
この手順では、Snow LeopardRedmineを動かすことができません。
こちらの手順を推奨します。


■さらに追記
Snow LeopardRedmineを導入する方法をまとめました。Snow LeopardにRedmineを導入まとめ - sugarballの日記こちらの方がわかりやすいかもしれません。。

Rubyの確認

macmini:~ sugarball$ ruby --version
ruby 1.8.7 (2008-08-11 patchlevel 72) [universal-darwin10.0]

Rubyよし。

RubyGemsの確認

macmini:~ sugarball$ gem --version
1.3.1

RubyGemsよし。

Ruby On Railsの確認

macmini:~ sugarball$ rails --version
Rails 2.2.2

RoRよし。

MySQLのインストール

Snow Leopardには標準でインストールされていないので、MacPortsを使ってインストール。
「+server」はObsolete(旧式)なので、代わりに「-server」を使うらしい。インストールには10分近くかかったと思う。

macmini:~ sugarball$ port variants mysql5
mysql5 has the variants:
   server: Obsolete; install mysql5-server port instead
   universal: Build for multiple architectures
macmini:~ sugarball$ sudo port install mysql5-server
Password:
--->  Computing dependencies for mysql5-server
--->  Fetching zlib
--->  Attempting to fetch zlib-1.2.3.tar.bz2 from http://distfiles.macports.org/zlib
--->  Verifying checksum(s) for zlib
--->  Extracting zlib
--->  Applying patches to zlib
--->  Configuring zlib
--->  Building zlib
--->  Staging zlib into destroot
--->  Installing zlib @1.2.3_3
--->  Activating zlib @1.2.3_3
--->  Cleaning zlib
--->  Fetching openssl
--->  Attempting to fetch openssl-0.9.8k.tar.gz from http://distfiles.macports.org/openssl
--->  Verifying checksum(s) for openssl
--->  Extracting openssl
--->  Applying patches to openssl
--->  Configuring openssl
--->  Building openssl
--->  Staging openssl into destroot
--->  Installing openssl @0.9.8k_0+darwin
--->  Activating openssl @0.9.8k_0+darwin
--->  Cleaning openssl
--->  Fetching ncursesw
--->  Attempting to fetch ncurses-5.7.tar.gz from ftp://ftp.dti.ad.jp/pub/GNU/ncurses
--->  Verifying checksum(s) for ncursesw
--->  Extracting ncursesw
--->  Configuring ncursesw
--->  Building ncursesw
--->  Staging ncursesw into destroot
--->  Installing ncursesw @5.7_0+darwin_10
--->  Activating ncursesw @5.7_0+darwin_10
--->  Cleaning ncursesw
--->  Fetching ncurses
--->  Verifying checksum(s) for ncurses
--->  Extracting ncurses
--->  Configuring ncurses
--->  Building ncurses
--->  Staging ncurses into destroot
--->  Installing ncurses @5.7_0+darwin_10
--->  Activating ncurses @5.7_0+darwin_10
--->  Cleaning ncurses
--->  Fetching readline
--->  Attempting to fetch readline-6.0.tar.gz from ftp://ftp.dti.ad.jp/pub/GNU/readline
--->  Verifying checksum(s) for readline
--->  Extracting readline
--->  Applying patches to readline
--->  Configuring readline
--->  Building readline
--->  Staging readline into destroot
--->  Installing readline @6.0.000_2+darwin
--->  Activating readline @6.0.000_2+darwin
--->  Cleaning readline
--->  Fetching mysql5
--->  Attempting to fetch mysql-5.0.86.tar.gz from http://mysql.he.net/Downloads/MySQL-5.0/
--->  Verifying checksum(s) for mysql5
--->  Extracting mysql5
--->  Applying patches to mysql5
--->  Configuring mysql5
--->  Building mysql5
--->  Staging mysql5 into destroot
--->  Installing mysql5 @5.0.86_0
--->  Activating mysql5 @5.0.86_0
--->  Cleaning mysql5
--->  Fetching mysql5-server
--->  Verifying checksum(s) for mysql5-server
--->  Extracting mysql5-server
--->  Configuring mysql5-server
--->  Building mysql5-server
--->  Staging mysql5-server into destroot
--->  Creating launchd control script
###########################################################
# A startup item has been generated that will aid in
# starting mysql5-server with launchd. It is disabled
# by default. Execute the following command to start it,
# and to cause it to launch at startup:
#
# sudo launchctl load -w /Library/LaunchDaemons/org.macports.mysql5.plist
###########################################################
--->  Installing mysql5-server @5.0.86_0
******************************************************
* In order to setup the database, you might want to run
* sudo -u mysql mysql_install_db5
* if this is a new install
******************************************************
--->  Activating mysql5-server @5.0.86_0
--->  Cleaning mysql5-server
macmini:~ sugarball$ mysql5 --version
mysql5  Ver 14.12 Distrib 5.0.86, for apple-darwin10.0.0 (i386) using readline 6.0

mysqlよし。ちなみに、実体は /opt/local/lib/mysql5/bin/mysql になる。

macmini:~ sugarball$ ls -la /opt/local/bin/mysql5
lrwxr-xr-x  1 root  admin  31 Oct 11 18:37 /opt/local/bin/mysql5 -> /opt/local/lib/mysql5/bin/mysql

と思ってたら、mysql_install_db5コマンドを実行しないといけないっぽい。

macmini:~$ ls -la /opt/local/bin/mysql_install_db5
lrwxr-xr-x  1 root  admin  42 Oct 11 18:37 /opt/local/bin/mysql_install_db5 -> /opt/local/lib/mysql5/bin/mysql_install_db
macmini:~ sugarball$ sudo /opt/local/bin/mysql_install_db5 --user=mysql
Password:
Installing MySQL system tables...
091011 19:04:08 [Warning] Setting lower_case_table_names=2 because file system for /opt/local/var/db/mysql5/ is case insensitive
OK
Filling help tables...
091011 19:04:08 [Warning] Setting lower_case_table_names=2 because file system for /opt/local/var/db/mysql5/ is case insensitive
OK

To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:
/opt/local/lib/mysql5/bin/mysqladmin -u root password 'new-password'
/opt/local/lib/mysql5/bin/mysqladmin -u root -h macmini.local password 'new-password'

Alternatively you can run:
/opt/local/lib/mysql5/bin/mysql_secure_installation

which will also give you the option of removing the test
databases and anonymous user created by default.  This is
strongly recommended for production servers.

See the manual for more instructions.

You can start the MySQL daemon with:
cd /opt/local ; /opt/local/lib/mysql5/bin/mysqld_safe &

You can test the MySQL daemon with mysql-test-run.pl
cd mysql-test ; perl mysql-test-run.pl

Please report any problems with the /opt/local/lib/mysql5/bin/mysqlbug script!

The latest information about MySQL is available on the web at
http://www.mysql.com
Support MySQL by buying support/licenses at http://shop.mysql.com

設定ファイルのコピー(バックアップ?)、編集。
こちらを参考にして、「mysqld」セクションに次の3行を追加した。

macmini:~ sugarball$ sudo cp /opt/local/share/mysql5/mysql/my-small.cnf /opt/local/etc/mysql5/my.cnf
macmini:~ sugarball$ sudo vi /opt/local/etc/mysql5/my.cnf
…
[mysqld]## USER-SETTINGS
default-character-set = utf8
default-storage-engine=innodb
skip-character-set-client-handshake
##

MySQLの起動、パスワードの設定、自動起動

macmini:~ sugarball$ sudo /opt/local/share//mysql5/mysql/mysql.server start
Starting MySQL
macmini:~ sugarball$ /opt/local/lib/mysql5/bin/mysqladmin -u root password '(パスワード)'
macmini:~ sugarball$ mysql5 -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 16
Server version: 5.0.86 Source distribution

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> quit
Bye

ここまではOK。しかし、下のコマンドが実行できなかった。何故?

macmini:~ sugarball$ /opt/local/lib/mysql5/bin/mysqladmin -u root -h macmini.local password '(パスワード)'
/opt/local/lib/mysql5/bin/mysqladmin: connect to server at 'macmini.local' failed
error: 'Host 'xxx.xxx.xxx.xxx' is not allowed to connect to this MySQL server'

調べてもよくわからない&別に実行しなくても問題無さそうなのでここはすっとばすことにした。あとは、自動起動の設定をする。

macmini:~ sugarball$ sudo launchctl load -w /Library/LaunchDaemons/org.macports.mysql5.plist

Redmine用のデータベース・ユーザーの作成

データベースredmineを作成して、さらにユーザーredmineを作成、redmineユーザーはデータベースredmineに対して全ての権限を持つようにする。

macmini:~ sugarball$ mysql5 -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 19
Server version: 5.0.86 Source distribution

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> create database redmine default character set utf8;
Query OK, 1 row affected (0.00 sec)

mysql> grant all privileges on redmine.* to redmine identified by '(Redmine用パスワード)';
Query OK, 0 rows affected (0.00 sec)

mysql> select user,host,password from mysql.user;
+---------+---------------+-------------------------------------------+
| user    | host          | password                                  |
+---------+---------------+-------------------------------------------+
| root    | localhost     | *(暗号化されたパスワード)               |
            …
| redmine | %             | *(暗号化されたパスワード)               |
+---------+---------------+-------------------------------------------+
6 rows in set (0.00 sec)

mysql> exit
Bye

RubyGemsMySQL用データベースドライバをインストール

Snow Leopardにmysqlのgemを入れるおまじない - レオメモ - s21gとか、その他のサイトを読んでると、mysql gemのインストールは64bitのgemを強制的に指定してやる必要があるそうな。

で、実行してみた。うーん。どうにも「No definition for next_result」やら「No definition for field_name」のメッセージが大量に表示される。とりあえず、gem listに表示されるので、これでよしとするか。*1

macmini:~ sugarball$ sudo env ARCHFLAGS="-arch x86_64" gem install mysql -- --with-mysql-config=/opt/local/lib/mysql5/bin/mysql_config
Password:
Building native extensions.  This could take a while...
Successfully installed mysql-2.8.1
1 gem installed
Installing ri documentation for mysql-2.8.1...

No definition for next_result

No definition for field_name

…以下略

macmini:~ sugarball$ gem list | grep mysql
mysql (2.8.1)

Redmineのインストール

http://redmine.jp/ から、最新版をインストールする。2009年10月11日現在では、0.8.5が最新だった。

redmine-0.8.5.tar.gzを展開し、展開後のフォルダを適当な位置にコピーする。別にウェブサーバーのドキュメントルートとかに置かなくてもいい。

macmini:Download sugarball$ mv ./redmine-0.8.5 ~/Library/

database.ymlの編集

macmini:redmine sugarball$ cp ./config/database.yml.example ./config/database.yml
macmini:redmine sugarball$ vi ./config/database.yml
# MySQL (default setup).  Versions 4.1 and 5.0 are recommended.
#
# Get the fast C bindings:
#   gem install mysql
#   (on OS X: gem install mysql -- --include=/usr/local/lib)
# And be sure to use new-style password hashing:
#   http://dev.mysql.com/doc/refman/5.0/en/old-client.html

production:
  adapter: mysql
  database: redmine
  host: localhost
  username: root
  password: (redmine用に設定したパスワード)
  encoding: utf8

…以下略

email.ymlの編集

今回はemail機能を使わないのでパス。

Redmineデータベースの初期化

どうやら、やはりダメっぽい。MacPortsMySQLをインストールしたのがダメだったか…
というわけで、ここのとおり、MacPortsからでなく、64bit版バイナリからMySQLをインストールしてやりなおし。

macmini:redmine sugarball$ rake db:migrate RAILS_ENV=production
(in /Users/sugarball/Library/redmine)
rake aborted!
uninitialized constant MysqlCompat::MysqlRes

(See full trace by running task with --trace)

その2へ続く…

*1:どなたか、解決方法があれば教えてくださいませ。