CentOS6.2にPassengerをインストールしてApacheと紐付けます。
■前提条件
・CentOS release 6.2 (Final)
・Ruby 2.1.2
・Rails 4.1.2
・複数のRailsアプリケーションを一台のサーバーで稼動させることは想定していない
・Railsアプリケーション以外を稼働させることは想定していない
■事前準備
足りないパッケージをインストールします(すでにインストール済なら飛ばします)。
[bash gutter=”0″]
# yum -y install curl-devel httpd-devel
[/bash]
■インストール
(1)Passengerをインストールします。
[bash gutter=”0″]
# gem install –no-ri –no-rdoc passenger
Fetching: daemon_controller-1.2.0.gem (100%)
Successfully installed daemon_controller-1.2.0
Fetching: passenger-4.0.45.gem (100%)
Building native extensions. This could take a while…
Successfully installed passenger-4.0.45
2 gems installed
[/bash]
(2)Apacheモジュールをインストールします。
[bash gutter=”0″]
# passenger-install-apache2-module
Welcome to the Phusion Passenger Apache 2 module installer, v4.0.45.
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.
[/bash]
ここで止まるのでEnterキーを押下します。
[bash gutter=”0″]
——————————————–
Which languages are you interested in?
Use <space> to select.
If the menu doesn’t display correctly, press ‘!’
‣ ⬢ Ruby
⬡ Python
⬡ Node.js
⬡ Meteor
[/bash]
言語を訊いてくるので、ここではRubyのみ選択(上下カーソルキーで移動、Spaceキー押下で選択/解除)してEnterキーを押下します。
[bash gutter=”0″]
linking shared-object passenger_native_support.so
——————————————–
Almost there!
Please edit your Apache configuration file, and add these lines:
LoadModule passenger_module /usr/local/rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/passenger-4.0.45/buildout/apache2/mod_passenger.so
<IfModule mod_passenger.c>
PassengerRoot /usr/local/rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/passenger-4.0.45
PassengerDefaultRuby /usr/local/rbenv/versions/2.1.2/bin/ruby
</IfModule>
After you restart Apache, you are ready to deploy any number of web
applications on Apache, with a minimum amount of configuration!
Press ENTER to continue.
[/bash]
少し時間がかかりますが、ここで止まるので、
[bash gutter=”0″]
<IfModule mod_passenger.c>
PassengerRoot /usr/local/rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/passenger-4.0.45
PassengerDefaultRuby /usr/local/rbenv/versions/2.1.2/bin/ruby
</IfModule>
[/bash]
をコピーしてどこかに保持し、Enterキーを押下します。
[bash gutter=”0″]
——————————————–
Deploying a web application: an example
Suppose you have a web 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
# Uncomment this if you’re on Apache >= 2.4:
#Require all granted
</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/local/rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/passenger-4.0.45/doc/Users guide Apache.html
https://www.phusionpassenger.com/documentation/Users%20guide%20Apache.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.
[/bash]
ここでインストールが終わります。
[bash gutter=”0″]
<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
# Uncomment this if you’re on Apache >= 2.4:
#Require all granted
</Directory>
</VirtualHost>
[/bash]
をコピーしてどこかに保持し、Enterキーを押下します。
(3)passengerが組み込まれたかどうか確認します。
[bash gutter=”0″]
# apachectl -M | grep passenger
[/bash]
[bash gutter=”0″]
passenger_module (shared)
Syntax OK
[/bash]
大丈夫そうです。
(4)httpd.confを編集します。
[bash gutter=”0″]
# vi /etc/httpd/conf/httpd.conf
[/bash]
NameVirtualHost *:80の行のコメントを外します。
[bash]
NameVirtualHost *:80
[/bash]
最終行に先程コピーした以下の内容を貼り付けます。
[bash]
<IfModule mod_passenger.c>
PassengerRoot /usr/local/rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/passenger-4.0.45
PassengerDefaultRuby /usr/local/rbenv/versions/2.1.2/bin/ruby
</IfModule>
[/bash]
(5)vhost.confを生成します。
[bash gutter=”0″]
# vi /etc/httpd/conf.d/vhost.conf
[/bash]
最終行に先程コピーした以下の内容を貼り付けます。
[bash]
<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
# Uncomment this if you’re on Apache >= 2.4:
#Require all granted
</Directory>
</VirtualHost>
[/bash]
www.yourhost.com や /somewhere/public はあくまでも例ですので、環境に応じて実在する値に書き換えてください。なお、Passengerはデフォルトだとproductionモードで動作しますので、Rails側がdevelopmentのモードの場合はvhost.confに下記を追記します。
[bash]
RailsEnv development
[/bash]
(6)apacheを起動します。
[bash gutter=”0″]
# service httpd start
[/bash]
(7)http://サーバーのアドレス/ で正しく参照できたら終了です。