Passengerのインストール

参考にしたサイト

http://redmine.jp/tech_note/apache-passenger/

これを見ながらやれば普通はできるはずなんだろうが、いろいろとひっかかったところがあったのでメモ。

動いたときの環境

# cat /etc/issue
CentOS release 5.4 (Final)
Kernel \r on an \m

# uname -a
Linux ip-10-130-34-195 2.6.21.7-2.fc8xen #1 SMP Fri Feb 15 12:39:36 EST 2008 i686 i686 i386 GNU/Linux

# ruby -v
ruby 1.8.7 (2010-01-10 patchlevel 249) [i386-linux]

# rpm -qa | grep -i mysql
MySQL-shared-compat-5.1.46-1.rhel5
ruby-mysql-2.7.3-1.el5
MySQL-client-community-5.0.90-0.rhel5
php-mysql-5.3.2-1.el5.remi
MySQL-devel-community-5.0.90-0.rhel5
MySQL-server-community-5.0.90-0.rhel5

# gem -v
1.3.6

# gem list

*** LOCAL GEMS ***

actionmailer (2.3.5)
actionpack (2.3.5)
activerecord (2.3.5)
activeresource (2.3.5)
activesupport (2.3.5)
fastthread (1.0.7)
oauth (0.4.0)
passenger (2.2.11)
rack (1.1.0, 1.0.1)
rails (2.3.5)
rake (0.8.7)
rubygems-update (1.3.6)

エラーと解決

Welcome aboard の「About your application’s environment」

Railsでプロジェクトを作成したらまずこのページを確認すると思われるが、ここでいきなりつまづいた。
まぁ今回はいろいろダメだったので当たり前といえば当たり前だが、注意点としては、

  • production モードでは無効。

クリックすると、

We're sorry, but something went wrong.
We've been notified about this issue and we'll take a look at it shortly.

と言われる。そういうもんらしい。
本家のドキュメントでは見つけられませんでしたが、掲示板に書いている人がいました。

the "properties" listing
will not be done for an external request or for the production
environemt.

http://www.ruby-forum.com/topic/186012
Passenger用の設定
  • error_log
[Mon May 03 11:51:49 2010] [error] *** Passenger could not be initialized because of this error:
The 'PassengerRoot' configuration option is not specified. This option is required, so please specify it.
TIP: The correct value for this option was given to you by 'passenger-install-apache2-module'.

httpd.conf の中に「PassengerRoot」の設定がない。
Passengerの初期インストール方法をもう一度確認。

  • 設定ファイル例
<VirtualHost _default_:80>
    DocumentRoot   /path/to/#{RAILS_ROOT}/public
    ServerName     localhost

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

	<Directory /var/lib/sekiar/public>
	  AllowOverride all
	  Options -MultiViews
	</Directory>
</VirtualHost>
gem のバージョンでも蹴られるらしい。
  • error_log
 Rails requires RubyGems >= 1.3.2 (you have 1.3.1). Please `gem update --system` and try again.

エラーメッセージに書いてある通りにgem をupdate すればよい。

  • 対処
# gem update --system
gem でmysql を入れろと言ってくる。
  • error_log
!!! The bundled mysql.rb driver has been removed from Rails 2.2. Please install the mysql gem and try again: gem install mysql.

実はこれを入れても(前提の環境じゃ)動かない。後述するRPM のパッケージを入れる必要がある。

abstract_adapter.rb:40: [BUG] Segmentation fault
  • error_log
/usr/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/connection_adapters/abstract_adapter.rb:40: [BUG] Segmentation fault
 ruby 1.8.7 (2010-01-10 patchlevel 249) [i386-linux]

Aborted

こいつが一番わかりにくかった。
ruby からMySQLへの接続がうまくいってないことが原因。(おそらく。)

  • 対処
# yum install ruby-mysql
  • ヒントにしたサイト

the problem is that starting from rails 2.2, mysql support is not
included by default
(sqlite3 is the new default) and you have to install it as a gem
so i assume you did "gem install mysql" or something similar.

http://old.nabble.com/ruby-mysql-error-td21334623.html
Premature end of script headers
  • error_log
[Mon May 03 12:36:07 2010] [error] [client 219.110.149.172]
 Premature end of script headers: rails, referer: http://localhost/

#{RAILS_ROOT} のパーミッションがroot のままだったりすると出るエラー。
apache がtmp に書き込んだりするので、パーミッションをコントロールしてやるとよい。

  • 対処
# chown apache:apache -R /path/to/#{RAILS_ROOT}
  • ヒントになったサイト

“Premature end of script headers” error basically means that script stopped for whatever reason before it returned any output to the web server. And, the problem in my case was that Apache user did not have read/write access to the directory where Rails application is located.

http://dalibornasevic.com/posts/7-premature-end-of-script-headers-ruby-on-rails-with-phusion-passenger-on-apache-error

いじょー。