Redmine2.2 インストールしたよ

Redmineのインストール - Redmineガイド

Ruby(Ruby on Rails)の知識が乏しかったので苦労した。
公式マニュアル通りインストールしたけど、なんやかんやで環境が整っていなかったのでそれも併せた構築メモ。

  • サーバのOSはFedora14。
  • データベースには、MySQLを使用。

Redmine本体をダウンロード

既にSubversionがインストール済みの環境なので、SVNリポジトリからダウンロード。
インストールしたいディレクトリに移動してSVNコマンド実行

svn checkout http://svn.redmine.org/redmine/branches/2.2-stable redmine

Redmineを動かす為の環境構築

以下redmineをコピーしたディレクトリ内で実行。
公式マニュアル通りに gem install bundle から bundle install 実行したのだけれども、色々ライブラリ等足りなかったみたいでエラー出まくり。
エラーメッセージ(キャプチャ忘れた)を順に対応していった結果が以下のコマンド。
足りない物は全てyumコマンドからインストール可能でした。
suでroot権限に昇格するかsudoコマンドで実行する。

gem install bundle
yum install ruby-devel
yum install gcc 
yum install ruby-mysql
yum install mysql-devel
yum install ImageMagick-devel
gem install rails
bundle install --without development test postgresql sqlite

データベース構築

無事本体のインストールが終わったので、次はデータベース構築。
既にMySQL自体の構築は終わっていたのでSQL実行のみ。
データベース作成とユーザー作成を行う。MySQLにrootでログインして以下を実行。

  • データベース名はredmine
  • 接続するアカウント名はremineuser
  • 接続アカウントのパスワードはreminepass (実際には推測されにくい文字列にしよう!)
CREATE DATABASE redmine;
GRANT ALL PRIVILEGES ON redmine.* TO redmineuser@localhost IDENTIFIED BY 'redminepass';

構築した環境に合わせて設定ファイルを作成。
config/database.ymlを作成。config/database.yml.EXAMPLEからコピーすると簡単。
production環境のみをyamlファイルに記載。

production:
  adapter: mysql
  database: redmine
  host: localhost
  username: redmineuser
  password: redminepass
  encoding: utf8

これでRedmineからDBにつながるようになったので、テーブルとデフォルトのレコードをInsert。
これらは公式マニュア通り実行。

rake generate_secret_token
RAILS_ENV=production rake db:imigrate
RAILS_ENV=production rake redmine:load_default_data

Apacheと連携

Apache上でRuby on Railsアプリケーションを動かす/Passenger(mod_rails for Apache)の利用 — Redmine.JP

Passengerを使って、ApacheモジュールとしてRedmineを動かせるように構築。
Passenderをインストールしてpassenger-install-apache2-moduleコマンドを実行すればいい。

gem install passenger
passenger-install-apache2-module

だけじゃなかった (T_T)

Welcome to the Phusion Passenger Apache 2 module installer, v3.0.19.

This installer will guide you through the entire installation process. It
shouldn't take more than 3 minutes in total.

Here's what you can expect from the installation process:

 1. The Apache 2 module will be installed for you.
 2. You'll learn how to configure Apache.
 3. You'll learn how to deploy a Ruby on Rails application.

Don't worry if anything goes wrong. This installer will advise you on how to
solve any problems.

Press Enter to continue, or Ctrl-C to abort.

--------------------------------------------

Checking for required software...

 * GNU C++ compiler... not found
 * Curl development headers with SSL support... not found
 * OpenSSL development headers... found
 * Zlib development headers... not found
 * Ruby development headers... found
 * OpenSSL support for Ruby... found
 * RubyGems... found
 * Rake... found at /usr/bin/rake
 * rack... found
 * Apache 2... found at /usr/sbin/httpd
 * Apache 2 development headers... not found
 * Apache Portable Runtime (APR) development headers... not found
 * Apache Portable Runtime Utility (APU) development headers... not found

Some required software is not installed.
But don't worry, this installer will tell you how to install them.

Press Enter to continue, or Ctrl-C to abort.

色々足りないって怒られちった。
not foundで指定されたライブラリをインストール。以下のコマンドを実行すれば大丈夫。

yum install gcc-c++ httpd-devel libcurl-devel

再度passenger-install-apache2-moduleコマンドを実行すればok。
最後の方にApacheの設定ファイルのサンプルが出力されるのでキャプチャ。
モジュール読み込みの設定。

The Apache 2 module was successfully installed.

Please edit your Apache configuration file, and add these lines:

   LoadModule passenger_module /usr/lib/ruby/gems/1.8/gems/passenger-3.0.19/ext/apache2/mod_passenger.so
   PassengerRoot /usr/lib/ruby/gems/1.8/gems/passenger-3.0.19
   PassengerRuby /usr/bin/ruby

After you restart Apache, you are ready to deploy any number of Ruby on Rails
applications on Apache, without any further Ruby on Rails-specific
configuration!

Press ENTER to continue.

こっちはVertualHost設定のサンプルをキャプチャ。

Deploying a Ruby on Rails application: an example

Suppose you have a Rails application in /somewhere. Add a virtual host to your
Apache configuration file and set its DocumentRoot to /somewhere/public:

   <VirtualHost *:80>
      ServerName www.yourhost.com
      # !!! Be sure to point DocumentRoot to 'public'!
      DocumentRoot /somewhere/public    
      <Directory /somewhere/public>
         # This relaxes Apache security settings.
         AllowOverride all
         # MultiViews must be turned off.
         Options -MultiViews
      </Directory>
   </VirtualHost>

And that's it! You may also want to check the Users Guide for security and
optimization tips, troubleshooting and other useful information:

  /usr/lib/ruby/gems/1.8/gems/passenger-3.0.19/doc/Users guide Apache.html

Enjoy Phusion Passenger, a product of Phusion (www.phusion.nl) :-)
https://www.phusionpassenger.com

Phusion Passenger is a trademark of Hongli Lai & Ninh Bui.

パーミッション変更

Passengerはrailsのconfig/environment.rbファイルのオーナーで実行するらしので所有者変更。
Passengerの実行ユーザーをapacheにしたいのでchmod実行でついでに全てのファイルオーナーをapacheに。

chown -R apache:apache /path/to/redmine/public

Apacheの設定

先ほどのPassengerインストール時に現れたサンプルを元にApacheの設定。
モジュール読み込み設定はhttp.confに記載して、それ以外の固有の設定はredmine.confという新たに作成したファイルに記載する。
そしてVirtualHostで分けていない環境なので、サブディレクトリにredmineを配置。
http://servername/redmine で起動できるようにする。

サブディレクトリで実行させるためには

と言った内容が当たり前のように書かれている。
なのに、403エラーになった。

[Redmine Rails] Passenger がシンボリックリンクを解決してくれない | Javable.Jp

偶然見つけたブログのおかげで解決できたので最終的な設定を。
要約すると、今回使ったPassengerではデフォルトではシンボリックリンクに対応していないと。
それを設定ファイルに明記すれば使えるんだぜ。PassengerAppRoot大事。
後は、RailsBaseURIとAliasを設定すればおk。

/etc/httpd/conf.d/redmine.conf

PassengerAppRoot /var/www/redmine
RailsBaseURI /redmine
Alias /redmine /var/www/redmine/public

<Directory /var/www/redmine/public>
    Options -MultiViews -Indexes -FollowSymLinks -ExecCGI
    Allowoverride on
</Directory>

Redmineのインストールは苦労するって噂を以前聞いた事あったけど・・・苦労し過ぎorz
インストールに一日半かかったがな :(
でもこれで、次からは楽にできるかな。


次がこない事を祈ろう。

はまった(2013-03-15追記)

OSをアップデートしたらうごかなくなった。
ブラウザからアクセスでも、rakeコマンド実行でも同じ内容のエラーが返る。

Please install the mysql adapter: `gem install activerecord-mysql-adapter` (mysql is not part of the bundle. Add it to Gemfile.)

どうやら、database.ymlのadapter項目を「mysql2」としなければならないようだ。
それに合わせて、mysql2, activerecord-mysql2-adapter をインストールしなければならない。
本来であれば、bundle install でmysql2がインストール&設定されるんだけど、アップデート行ったせいで整合性がとれなくなったみたい。
共有の場所にインストールすると整合性の不具合とかおきそうなので、redmineのローカル内に再インストール。

bundle install --path vender/bundler --without development test postgresql sqlite


あれ?
エラー再発で括弧の中身が変わった。(cannot load such file -- mysql2/mysql2) とかなったけど・・・
試行錯誤の末、端末再起動で解決した。キャッシュか?原因不明・・・

追記

サーバを再起動したら、403エラーでた。
Apacheのエラーログしらべたら、「Unable to start the Phusion Passenger watchdog」なるものが。
ググった結果、SELinuxが関係している事が判明。
環境構築中の記憶の片隅にあった記憶を思い出す。

「とりあえず、setenforce 0 実行しておくか。」

setenforceコマンドは再起動後は元の設定に戻ってしまうのでこれが原因。
ちゃんと設定しないとだけど、とりあえずsetenforce 0実行しておくか。
(後日繰り返しw

追記2(2013-15-09)

Subversionと連携したけれど、「リポジトリに、エントリ/リビジョンが存在しません。」とエラーな感じ。
試しに、redmineを動かしているアカウントで下記のコマンドを実行してみる。

sudo -u redmineアカウント svn list --xml https://svnのドメイン/リポジトリ

あらまぁそりゃそうだ。オレオレ証明書だからエラー出してる・・・

'https://svnのドメイン:443' のサーバ証明書の認証中にエラーが発生しました:
 - 証明書は信頼のおける機関が発行したものではありません。証明書を手動で認証
   するためにフィンガープリントを用いてください!

つわけで、redmine自体にオレオレ証明書を無視する様に修正する。
/path/to/redmine/lib/redmine/scm/adapters/subversion_adapter.rb の 263行目に --trust-server-cert を追加。(/path/to/はredmineがインストールされてるパスに置き換える)

        def credentials_string
          str = ''
          str << " --username #{shell_quote(@login)}" unless @login.blank?
          str << " --password #{shell_quote(@password)}" unless @login.blank? || @password.blank?
          str << " --no-auth-cache --non-interactive --trust-server-cert"
          str
        end

後はApacheを再起動することで無事に読み込み完了。

参考サイト