apache de ruby on rails

apache に rails を組み込むモジュール「Passenger(mod_rails for Apache)」のインストールメモ。
OSはubuntu 8.0.4で、以下がインストール済みとする。

・Apache 2.2.8
・rails 2.0.2
・rubygems 0.9.4


(1) mod_rewriteを有効にする

$ sudo a2enmod rewrite

(2) Passengerのインストール

$ sudo gem install passenger

fastthread をインストールするか聞かれました。もちろん「Y」で。
上記コマンドによりインストールされる passenger-install-apache2-module を実行。
$ sudo /var/lib/gems/1.8/bin/passenger-install-apache2-module

Welcome to the Phusion Passenger Apache 2 module installer, v2.0.1.

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++
* Ruby development headers... found
* OpenSSL support for Ruby... found
* RubyGems... found
* Rake... found at /usr/bin/rake
* Apache 2... found at /usr/sbin/apache2
* Apache 2 development headers... not found
* Apache Portable Runtime (APR) development headers... found
* fastthread... not found
* rack... 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.

あれ?さっき fastthread はインストールされたと思ったのだが。。。
Installation instructions for required software

* To install Apache 2 development headers:
Please run apt-get install apache2-prefork-dev as root.

* To install fastthread:
Please install RubyGems first, then run gem install fastthread

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

/var/lib/gems/1.8/gems/passenger-2.0.1/doc/Users guide.html

$ sudo apt-get install apache2-prefork-dev

$ sudo sudo apt-get update

$ sudo gem install fastthread
Need to update 1 gems from http://gems.rubyforge.org
Select which gem to install for your platform (i486-linux)
1. fastthread 1.0.1 (i386-mswin32)
2. fastthread 1.0.1 (ruby)
3. fastthread 1.0.1 (mswin32)
4. fastthread 1.0 (ruby)
5. fastthread 1.0 (mswin32)
6. Skip this gem
7. Cancel installation
> 2

無事入ったようなので、再度 passenger-install-apache2-module に挑戦。
$ sudo /var/lib/gems/1.8/bin/passenger-install-apache2-module

The Apache 2 module was successfully installed.

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

LoadModule passenger_module /var/lib/gems/1.8/gems/passenger-2.0.1/ext/apache2/mod_passenger.so
PassengerRoot /var/lib/gems/1.8/gems/passenger-2.0.1
PassengerRuby /usr/bin/ruby1.8

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

Press ENTER to continue.

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:

ServerName www.yourhost.com
DocumentRoot /somewhere/public

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

/var/lib/gems/1.8/gems/passenger-2.0.1/doc/Users guide.html

Enjoy Phusion Passenger, a product of Phusion (www.phusion.nl) :-)

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

Apacheの設定ファイルを編集します。設定ファイルをいじるのではなく、別途 passenger 用のファイルとして設定を追加。
$ sudo vi /etc/apache2/mods-available/passenger.load
LoadModule passenger_module /var/lib/gems/1.8/gems/passenger-2.0.1/ext/apache2/mod_passenger.so
PassengerRoot /var/lib/gems/1.8/gems/passenger-2.0.1
PassengerRuby /usr/bin/ruby1.8

$ sudo a2enmod passenger

$ sudo vi /etc/apache2/sites-available/rails

<VirtualHost *>
ServerName rails.example.com
DocumentRoot /home/yasu/rails
<Directory /rails>
AllowOverride All
Options All

$ sudo a2ensite rails

$ sudo /etc/init.d/apache2 restart

これで rails.example.com が有効になったはずです。

hostsに正しく設定し、ブラウザに htt://rails.example.com へアクセスすると。。。


Comment Form


→ この記事にトラックバックする(FC2ブログユーザー)