passengerというのはrailsで作ったアプリを80番ポートでapacheで動くようにしてくれるもの。apacheをソースからコンパイルし直す必要があるみたい。
後々、足りないと指摘されるので、事前に必要なモジュールをインストールしておく。
#yum -y install httpd-devel apr-devel apr-util-devel
passengerのインストール
$gem install passenger
$rbenv rehash
なぜかこのコマンド打たないとパスが通らないんだよね。
インストーラーを起動する。
$passenger-install-apache2-module
以後、適宜Enterを押していく。
-------------------------------------------
The Apache 2 module was successfully installed.
Please edit your Apache configuration file, and add these lines:
LoadModule passenger_module /home/xxxxxxxx/.rbenv/versions/2.0.0-p195/lib/ruby/gems/2.0.0/gems/passenger-4.0.2/libout/apache2/mod_passenger.so
PassengerRoot /home/xxxxxxxx/.rbenv/versions/2.0.0-p195/lib/ruby/gems/2.0.0/gems/passenger-4.0.2
PassengerDefaultRuby /home/xxxxxxxx/.rbenv/versions/2.0.0-p195/bin/ruby
<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>
こんな感じのログが出るので、この部分は控えてhttpd.confに追加すればいいようだ。
しかし、rbenvをユーザーのホームにインストールしたせいで、とても本番運用としては使えないパスになっちまった。
設定が終わったらapacheを起動してみる。
#service httpd start
Starting httpd: httpd: Syntax error on line 986 of /etc/httpd/conf httpd.conf: Cannot load /home/xxxxxxxx/.rbenv/versions/2.0.0-p195/lib/ruby/gems/2.0.0/gems/passenger-4.0.2/libout/apache2/mod_passenger.so into server: /home/xxxxxxxx/.rbenv/versions/2.0.0-p195/lib/ruby/gems/2.0.0/gems/passenger-4.0.2/libout/apache2/mod_passenger.so: cannot open shared object file: Permission denied [FAILED]
おろ、パーミッションがないって言われるぞ。
そういえば、CentOSはデフォルトでSELinuxが有効になっていた気がする。
ということでSELinuxを無効にしてしまおう。
/etc/selinux/configファイルの
SELINUX=enforcingの部分をSELINUX=disabledに変更する。
OS再起動。
まだパーミッションがないと言われます。
ここでは/home/xxxxxxxxというユーザーディレクトリにrailsアプリを作っているので、
/home/xxxxxxxxのディレクトリ権限は通常700になっています。
なので755に変えちゃいます。でないとapacheが配下のファイルにアクセスできません。
まだ動かない。
passengerはデフォルトでproductionモードで動くようになっているようです。
developmentモードでしか準備できていないので、この場合は
RailsEnv development
の行をhttpd.confに追加します。
<VirtualHost *:80/>
RailsEnv development
...
</VirtualHost>
やっと動いた。