嘘八百

Apacheとの連携(Passengerの構築)

Ruby on rails 3をApache上で実行するための環境構築。
Apacheと連携するにはPassengerが必要。
環境構築のログを残す。

1. Apach + Passengerの環境構築

■ gemコマンドからPassengerをインストール
# gem install passenger
Fetching: fastthread-1.0.7.gem (100%)
Building native extensions.  This could take a while...
Fetching: daemon_controller-0.2.6.gem (100%)
Fetching: passenger-3.0.9.gem (100%)
Successfully installed fastthread-1.0.7
Successfully installed daemon_controller-0.2.6
Successfully installed passenger-3.0.9
3 gems installed
Installing ri documentation for fastthread-1.0.7...
Installing ri documentation for daemon_controller-0.2.6...
Installing ri documentation for passenger-3.0.9...
Installing RDoc documentation for fastthread-1.0.7...
Installing RDoc documentation for daemon_controller-0.2.6...
Installing RDoc documentation for passenger-3.0.9...

成功。

■ Apacheモジュールとしてインストール
# passenger-install-apache2-module
Welcome to the Phusion Passenger Apache 2 module installer, v3.0.9.

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... found at /usr/bin/g++
 * Curl development headers with SSL support... not found
 * OpenSSL development headers... found
 * Zlib development headers... found
 * Ruby development headers... /usr/local/lib/ruby/gems/1.9.1/gems/passenger-3.0.9/lib/phusion_passenger/dependencies.rb:227: Use RbConfig instead of obsolete and deprecated Config.
found
 * OpenSSL support for Ruby... found
 * RubyGems... found
 * Rake... found at /usr/local/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.

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

Installation instructions for required software

 * To install Curl development headers with SSL support:
   Please run yum install curl-devel as root.

 * To install Apache 2 development headers:
   Please run yum install httpd-devel as root.

 * To install Apache Portable Runtime (APR) development headers:
   Please run yum install apr-devel as root.

 * To install Apache Portable Runtime Utility (APU) development headers:
   Please run yum install apr-util-devel as root.

If the aforementioned instructions didn't solve your problem, then please take
a look at the Users Guide:

  /usr/local/lib/ruby/gems/1.9.1/gems/passenger-3.0.9/doc/Users guide Apache.html

モジュール不足で失敗。以下の部分で判る。
* Curl development headers with SSL support... not found
* Apache 2 development headers... not found
* Apache Portable Runtime (APR) development headers... not found
* Apache Portable Runtime Utility (APU) development headers... not found

■ 必要なモジュールをインストール
# yum install curl-devel

成功。

yum install httpd-devel

成功。合わせてapr-devel、apr-util-develもインストールされた。

■ Apacheモジュールとしてインストール@2回目
# passenger-install-apache2-module

(メッセージ省略)

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

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

   LoadModule passenger_module /usr/local/lib/ruby/gems/1.9.1/gems/passenger- 3.0.9/ext/apache2/mod_passenger.so
   PassengerRoot /usr/local/lib/ruby/gems/1.9.1/gems/passenger-3.0.9
   PassengerRuby /usr/local/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.

--------------------------------------------
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
      DocumentRoot /somewhere/public    # <-- be sure to point to 'public'!
      <Directory /somewhere/public>
         AllowOverride all              # <-- relax Apache security settings
         Options -MultiViews            # <-- MultiViews must be turned off
      </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/lib/ruby/gems/1.9.1/gems/passenger-3.0.9/doc/Users guide Apache.html

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

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

成功。

■ Apachの設定ファイルにモジュールを追加
# vi /etc/httpd/conf.d/passenger.conf
---
# for Ruby on Rails 3. 2011/11/26
LoadModule passenger_module /usr/local/lib/ruby/gems/1.9.1/gems/passenger-3.0.9/ext/apache2/mod_passenger.so
PassengerRoot /usr/local/lib/ruby/gems/1.9.1/gems/passenger-3.0.9
PassengerRuby /usr/local/bin/ruby
---

■ DocumentRootの変更
# vi /etc/httpd/conf/httpd.conf
---
#DocumentRoot "/var/www/html"
DocumentRoot "(Rubyアプリケーション絶対パス)/public"
---

■ Apacheの再起動

# /etc/rc.d/init.d/httpd restart

■ 動作確認

Apacheの再起動後 http://localhost/ でアクセス成功。


2011-11-26