MacOSX(Leopard)にPassenger(1.0.4)入れる

MacApache上でRailsが起動できるPassengerをMacPort版のApache2との組み合わせでインストールしました。

rubygemでpassengerをインストール

$ sudo gem install passenger
Password:
Bulk updating Gem source index for: http://gems.rubyforge.org
Building native extensions.  This could take a while...
Building native extensions.  This could take a while...
Successfully installed rake-0.8.1
Successfully installed fastthread-1.0.1
Successfully installed passenger-1.0.4
3 gems installed
Installing ri documentation for rake-0.8.1...
Installing ri documentation for fastthread-1.0.1...

No definition for dummy_dump

No definition for dummy_dump

No definition for rb_queue_marshal_load

No definition for rb_queue_marshal_dump
Installing ri documentation for passenger-1.0.4...
Installing RDoc documentation for rake-0.8.1...
Installing RDoc documentation for fastthread-1.0.1...

No definition for dummy_dump

No definition for dummy_dump

No definition for rb_queue_marshal_load

No definition for rb_queue_marshal_dump
Installing RDoc documentation for passenger-1.0.4...
./doc/template/horo.rb:17: warning: already initialized constant FONTS
./doc/template/horo.rb:19: warning: already initialized constant STYLE
./doc/template/horo.rb:213: warning: already initialized constant XHTML_PREAMBLE
./doc/template/horo.rb:221: warning: already initialized constant HEADER
./doc/template/horo.rb:272: warning: already initialized constant FILE_PAGE
./doc/template/horo.rb:300: warning: already initialized constant CLASS_PAGE
./doc/template/horo.rb:338: warning: already initialized constant METHOD_LIST
./doc/template/horo.rb:486: warning: already initialized constant FOOTER
./doc/template/horo.rb:491: warning: already initialized constant BODY
./doc/template/horo.rb:503: warning: already initialized constant SRC_PAGE
./doc/template/horo.rb:531: warning: already initialized constant FR_INDEX_BODY
./doc/template/horo.rb:535: warning: already initialized constant FILE_INDEX
./doc/template/horo.rb:583: warning: already initialized constant CLASS_INDEX
./doc/template/horo.rb:584: warning: already initialized constant METHOD_INDEX
./doc/template/horo.rb:586: warning: already initialized constant INDEX
$

環境変数を弄る

passengerがMacPortでインストールしたモジュールを発見できるように環境変数を弄る。


環境変数を弄らずインストールした場合、モジュールが正しく選ばれず次のようになるので、環境変数を弄る。
環境変数を設定しなかった場合のログ

 * Apache 2... found at /usr/sbin/httpd
 * Apache 2 development headers... found at /usr/sbin/apxs
 * Apache Portable Runtime (APR) development headers... found at /Developer/SDKs/MacOSX10.5.sdk/usr/bin/apr-1-config

Port経由の場合はこれらが該当モジュール。
httpd … /opt/local/apache2/bin/httpd
aprx … /opt/local/apache2/bin/apxs
apr … /opt/local/bin/apr-1-config

$ export PATH=/opt/local/apache2/bin:$PATH
$ env | grep "^PATH"
PATH=/opt/local/apache2/bin:/opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin

念のために下記を参考に環境変数APXS2も設定してみる。
MacOSX 10.4 (Tiger) にPassenger (mod_rails for Apache) をインストール » RAILS PRESS

$ export APXS2=/opt/local/apache2/bin/apxs

Apache2への組み込み

$ sudo passenger-install-apache2-module
Password:
Welcome to the Passenger Apache 2 module installer.

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.

Enterを入力

Checking for required software...

 * GNU C++ compiler... found at /usr/bin/g++
 * Ruby development headers... found
 * OpenSSL support for Ruby... found
 * RubyGems... found
 * Rake... found at /usr/bin/rake
 * Apache 2... found at /opt/local/apache2/bin/httpd
 * Apache 2 development headers... found at /opt/local/apache2/bin/apxs
 * Apache Portable Runtime (APR) development headers... found at /opt/local/bin/apr-1-config
 * fastthread... found
--------------------------------------------

--------------------------------------------
Compiling and installing Apache 2 module...
cd /Library/Ruby/Gems/1.8/gems/passenger-1.0.4
rake clean apache2
(in /Library/Ruby/Gems/1.8/gems/passenger-1.0.4)
### In ext/apache2:
rm -rf Utils.o Logging.o Configuration.o Hooks.o mod_passenger.o mod_passenger.so

### In ext/passenger:
make clean
rm -f Makefile

### In ext/boost/src:
rm -f libboost_thread.a *.o

### In test:
rm -f Apache2ModuleTests *.o

### In benchmark:
rm -f DummyRequestHandler

### In ext/boost/src:
g++ -O2 -fPIC -I../.. -D_REENTRANT -DNDEBUG  -c *.cpp
ar cru libboost_thread.a *.o
ranlib: file: libboost_thread.a(tss_dll.o) has no symbols
ranlib: file: libboost_thread.a(tss_hooks.o) has no symbols
ranlib: file: libboost_thread.a(tss_null.o) has no symbols
ranlib: file: libboost_thread.a(tss_pe.o) has no symbols
ranlib libboost_thread.a
ranlib: file: libboost_thread.a(tss_dll.o) has no symbols
ranlib: file: libboost_thread.a(tss_hooks.o) has no symbols
ranlib: file: libboost_thread.a(tss_null.o) has no symbols
ranlib: file: libboost_thread.a(tss_pe.o) has no symbols

### In ext/apache2:
g++ -I.. -fPIC -g -DPASSENGER_DEBUG -DDARWIN -DSIGPROCMASK_SETS_THREAD_MASK -no-cpp-precomp -I/opt/local/include/apr-1 -I/opt/local/apache2/include -D_REENTRANT -Wall -g -I/usr/local/include  -c mod_passenger.c

### In ext/apache2:
g++ -I.. -fPIC -g -DPASSENGER_DEBUG -DDARWIN -DSIGPROCMASK_SETS_THREAD_MASK -no-cpp-precomp -I/opt/local/include/apr-1 -I/opt/local/apache2/include -D_REENTRANT -Wall -g -I/usr/local/include  -c Utils.cpp

### In ext/apache2:
g++ -I.. -fPIC -g -DPASSENGER_DEBUG -DDARWIN -DSIGPROCMASK_SETS_THREAD_MASK -no-cpp-precomp -I/opt/local/include/apr-1 -I/opt/local/apache2/include -D_REENTRANT -Wall -g -I/usr/local/include  -c Logging.cpp

### In ext/apache2:
g++ -I.. -fPIC -g -DPASSENGER_DEBUG -DDARWIN -DSIGPROCMASK_SETS_THREAD_MASK -no-cpp-precomp -I/opt/local/include/apr-1 -I/opt/local/apache2/include -D_REENTRANT -Wall -g -I/usr/local/include  -c Configuration.cpp

### In ext/apache2:
g++ -I.. -fPIC -g -DPASSENGER_DEBUG -DDARWIN -DSIGPROCMASK_SETS_THREAD_MASK -no-cpp-precomp -I/opt/local/include/apr-1 -I/opt/local/apache2/include -D_REENTRANT -Wall -g -I/usr/local/include  -c Hooks.cpp

### In ext/apache2:
g++ -flat_namespace -bundle -undefined dynamic_lookup Utils.o Logging.o Configuration.o Hooks.o mod_passenger.o -fPIC -o mod_passenger.so   -lstdc++ -lpthread ../boost/src/libboost_thread.a -L/opt/local/lib -lapr-1

### In ext/passenger:
ruby extconf.rb
creating Makefile

### In ext/passenger:
make
gcc -I. -I/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/universal-darwin9.0 -I/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/universal-darwin9.0 -I.  -fno-common -arch ppc -arch i386 -Os -pipe -fno-common  -c native_support.c
cc -arch ppc -arch i386 -pipe -bundle -undefined dynamic_lookup -o native_support.bundle native_support.o -L"." -L"/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib" -L. -arch ppc -arch i386    -lruby  -lpthread -ldl -lm


--------------------------------------------
The Apache 2 module was successfully installed.

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

   LoadModule passenger_module /Library/Ruby/Gems/1.8/gems/passenger-1.0.4/ext/apache2/mod_passenger.so
   RailsSpawnServer /Library/Ruby/Gems/1.8/gems/passenger-1.0.4/bin/passenger-spawn-server
   RailsRuby /System/Library/Frameworks/Ruby.framework/Versions/1.8/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.

Enterを入力

--------------------------------------------
Deploying a Ruby on Rails application: an example

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

   <VirtualHost *:80>
      ServerName www.yourhost.com
      DocumentRoot /somewhere/public
   </VirtualHost>

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

  /Library/Ruby/Gems/1.8/gems/passenger-1.0.4/doc/Users guide.html

Enjoy Passenger, a product of Phusion (www.phusion.nl) :-)
http://www.modrails.com/
$
 * Apache 2... found at /opt/local/apache2/bin/httpd
 * Apache 2 development headers... found at /opt/local/apache2/bin/apxs
 * Apache Portable Runtime (APR) development headers... found at /opt/local/bin/apr-1-config

とある。ちゃんと見つけてくれたようだ。

Apacheの設定

http.confのRails用の設定を作成する。

ServerNameで設定したURLで直接Railsアプリを走らせたい場合は、
DocumentRootに$RAILS_ROOTのpublicディレクトリを指定する。

サブディレクトリでRailsを走らせたい場合は、RailsBaseURIを使う。
Passenger users guide

$ sudo vi /opt/local/apache2/conf/extra/httpd-rails.conf
...()...
$ cat /opt/local/apache2/conf/extra/httpd-rails.conf
LoadModule passenger_module /Library/Ruby/Gems/1.8/gems/passenger-1.0.4/ext/apache2/mod_passenger.so
RailsSpawnServer /Library/Ruby/Gems/1.8/gems/passenger-1.0.4/bin/passenger-spawn-server
RailsRuby /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby

<VirtualHost *:80>
  ServerName WWW.EXAMPLE.COM
  DocumentRoot $RAILS_ROOT/public
  RailsEnv development
</VirtualHost>
$

rails用のhttpd-rails.confをhttpd.confから呼び出す

$ sudo vi /opt/local/apache2/conf/httpd.conf

次の一行を追加する

Include conf/extra/httpd-rails.conf

Apacheを再起動する。

$ sudo /opt/local/apache2/bin/apachectl restart

試しにRetrospectivaを動かしてみる

せっかくなので、Retrospectivaを公開できるように設定する。

$ sudo ln -s <svc coしたディレクトリ>/retrospectiva_dev/public /opt/local/apache2/htdocs/retro
$ sudo vi /opt/local/apache2/conf/extra/httpd-rails.conf

、、、なんかだめだ。500エラーになる。
ログが無いと解析できないなー。と思ってログを見てみたんですが、

$ tail /opt/local/apache2/logs/error_log
...()...
[38428:Hooks.cpp:400] Processing HTTP request: /retro
[38314:Application.h:264] Application 0x1f291c0: created.
$ tail /opt/local/apache2/logs/access_log
...()...
202.32.73.44 - - [07/May/2008:17:16:23 +0900] "GET /retro/ HTTP/1.0" 500 60

retrospectivaへのアクセスがあると、Passengerが起動されているっぽいが、うまく動いてない。
全然ログが残っていないため解析できない。

行き詰まったのでGoogleGroupでエライ人に聞いてみた。

phusion-passenger - Google Code
でIssueを探しても該当案件が見つからなかったので、GoogleGroup(Phusionの社員が常駐しているようだ)で聞いてみた。
successfully installed but not boot @MacOSX(Leopard) + Apache2(MacPort) - Phusion Passenger Discussions | Google グループ

結論

結局1.0.4での動作は断念しましたが、単にrakeしたときのRAILS_ENVとhttpd.confのRailsEnvが不一致であるためのエラーでした。
ここまでの設定で動作可能でした。(httpd.confでロードするモジュールを1.0.4用にして起動確認しました。)