4/12/2008

Passenger :Mod_rails for Apache 終於出世

這是 Rails 登基的最後一塊基石嗎?

不知道說了多少次,Apache 上面沒有 mod_rails,不能像是 php 一樣放上去就跑了,不過時代終於改變了,Mod_rails 出現了,他的名字叫做 Passenger

他做的事情就是讓設定Ruby on Rails 簡單到極點,省去所有設定繁複的設定手續,一個 Apache 就可以跑 Ruby on Rails。讓所有覺得 Ruby on Rails 設定困難的人全部閉嘴。 此東西一出,各方高手可都是讚譽有加

DHH : This could definitely become very popular, very fast ;)

Matz:It is often said that Rails is weak on deployment; PHP runs fairly fast just by uploading scripts. Rails is slow on development mode, and requires restarting on production mode (and bit complex to configure). modrails might be the answer for it.

效能
第一個問題是他的效能跟穩定性,跟現在市面上的 solution 有沒有得比。

根據他們自己的測試,看來是有大於 Mongrel,略贏過於 Thin 的效能。 Robustness 測試他們宣稱跟 Mongrel 一樣穩定,勝過 thin 還有 ebb。

安裝方式
既然是走簡單取向的 Apache ,那安裝方式當然要簡單點摟。只要你的 Server 上面有 Ruby / Rails / Gems / Apache2 ,那麼安裝方式就是兩下
1. gem i passenger
2. passenger-install-apache2-module

設定方式
既然是走簡單取向,設定方式要更簡單,你必須在 Apache 的 httpd.conf 裡面設定

LoadModule passenger_module passenger_module的預設目錄
RailsSpawnServer SpawnServer路徑
RailsRuby ruby路徑

別擔心找不到相關路徑,
screen-capture.png
上面的圖,我們可以看到在 passenger-install-apache2-module 過程中他會自動產生相關設定檔,給你貼上去。

剛剛是把 Rails 環境設定好,現在就是就是設定 DocumentRoot,

<VirtualHost *:80>
ServerName www.yourhost.com
DocumentRoot /rails目錄/public
</VirtualHost>

簡單講就是要設定清楚 Document Root,設定到Rails 目錄底下的 public 資料夾。,當然他也有範例 config 檔自動生成 XD
screen-capture-1.png


讓 Rails 跑在子目錄下
還沒測試,不過在 Doc 裡面有,看來可以很簡單的跑 PHP 跟 Rails 在同一個 Apache 下面(Bravo!!!)。

原理
採用類似 Apache mod_fastcgi 的方式,以一個 Passenger Process 來管理所需的 Rails process 量,隨著量的大小而動態增減 Process 數目。

結論
目前沒有明顯的結論,說 Passenger 一定勝過 Mongrel 或是 Lighttpd+fcgi 的 Solution。不過,看到他簡單的設定檔,還有看似不錯的效能跟穩定度,真的很值得期待。

4 則留言:

Unknown 提到...

按照步驟安裝只有看到 404 畫面 :/
apache 錯誤訊息也很奇怪呢
[6220:ApplicationPoolClientServer.h:426] Client 0x8243928: received message: ['get', '/home/shellingford/develope/ruby/eocamp08', 'true', 'nobody']
[6220:ApplicationPoolClientServer.h:426] Client 0x8243928: received message: ['close', '0']

thegiive 提到...

我 OSX 上面也有類似的 error
不過改到 CentOS 就可以了
Maybe try try Linux ?

匿名 提到...

這對RoR的開發者來說是個好消息 XD

Ryudo Awaru 提到...

慘哪~不能跟worker mpm搭配..
WARNING: Apache doesn't seem to be compiled with the 'prefork' MPM

Passenger has only been tested on Apache with the 'prefork' MPM. Your Apache
installation is compiled with the 'worker' MPM. We recommend you
to abort this installer and to recompile Apache with the 'prefork' MPM.
------------------------
可是又必需跑在worker下...orz