在 Ubuntu 下部屬 RoR 環境

前言

建構 Ubuntu + Rails + MySQL + Apache + mod_rails 的環境來部署 RoR 專案.

建構 RoR 環境

本章詳細步驟請參考: Ubuntu 6.06 架設 RoR

  1. 安裝 Ruby .
  2. 安裝 RubyGems .
  3. 安裝 Rails .
    遇到問題: no such file to load -- openssl (RuntimeError) .
    解法: 安裝 libopenssl-ruby . 參考: 主题:no such file to load -- openssl (RuntimeError)
  4. 產生 RoR 專案.
  5. 執行 RoR 專案.
    遇到問題: 沒有裝資料庫.
    解法: 資料庫問題不歸入 RoR 環境章節,下一章會處理此問題.

安裝 MySQL 資料庫

本章詳細步驟請參考: 在Ubuntu/Debian上面安裝Ruby on Rails的生產環境服務器

  1. 安裝 MySQL .
  2. 重設 root 密碼.
  3. 安裝 mysql 的 RubyGem 包以取得更好的效率.
    遇到問題: /usr/bin/gem:23: uninitialized constant Gem::GemRunner (NameError)
    解法: http://mmiwwcom.javaeye.com/blog/181074
  4. 在 MySQL 建立 Schema 測試與 RoR 專案的連接情形.
    遇到問題: database.yml 的 Socket 設定.
    解法: http://wiki.rubyonrails.org/rails/pages/database.yml

安裝 Apache

ubuntu 已經內建 Apache 2 . 可直接安裝,步驟可參考: 在Ubuntu/Debian上面安裝Ruby on Rails的生產環境服務器

安裝 mod_rails

本章詳細步驟請參考: Passenger :Mod_rails for Apache 終於出世

1. 安裝 mod_rails
遇到問題: ERROR: Error installing passenger:
ERROR: Failed to build gem native extension.

/usr/bin/ruby1.8 extconf.rb i passenger
extconf.rb:1:in `require': no such file to load -- mkmf (LoadError)
from extconf.rb:1
解法: http://d.hatena.ne.jp/rx7/20080412/p1

遇到問題: WARNING: Apache doesn't seem to be compiled with the 'prefork' MPM 解法: 執行 sudo apt-get install apache2-mpm-prefork apache2-prefork-dev

2. 在 Apache 設定檔( httpd.conf 在 /etc/apache2 )中新增以下設定:
設定 LoadModule passenger_module passenger_module 的預設目錄.
設定 RailsSpawnServer SpawnServer 路徑.
設定 RailsRuby ruby 路徑.
設定 DocumentRoot .

LoadModule passenger_module /usr/lib/ruby/gems/1.8/gems/passenger-1.0.5/ext/apache2/mod_passenger.so

RailsSpawnServer /usr/lib/ruby/gems/1.8/gems/passenger-1.0.5/bin/passenger-spawn-server

RailsRuby /usr/bin/ruby1.8

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

完成以上步驟,在瀏覽器中打上 www.yourhost.com 應該就能看到 RoR 專案已經正確被啟動!

進一步驗證(練習)

本章參考: <轉>Ruby on Rails: typo安裝指南 ,但啟動 Typo 部份是使用 Apache + mod_rails 的方法!

Typo 為一個用 RoR 開發的專案. 下載及其它 還不到網路發佈的步驟請參考<轉>Ruby on Rails: typo安裝指南 .

1. 以 Typo 為例,我將 Type 下載至 /home/server/webapps 下.

2. Apahce 的 httpd.conf 內修改 DocumnetRoot 設定如下:

<VirtualHost *:80>
ServerName localhost
DocumentRoot /home/server/webapps/typo/public
</VirtualHost>

3. 使用 sudo /etc/init.d/apache2 restart 重啟 Apache .

4. 在瀏覽器中打上 localhost 應該就能看到 Typo 被正確啟動!

練習部屬自己的 RoR 專案

問題: 嘗試透過瀏覽器開啟 RoR 專案,網頁總是發生 HTTP Error 403 Forbidden 或 Passenger error #2 錯誤.
解法: 根據 http://groups.google.com/group/phusion-passenger/browse_thread/thread/8313ef1ba14cbb07 ,發現確實是 Apache 無權限去存取我 RoR 專案中的 public 檔案夾(事實上是整個 RoR 專案),修改後便能排解此問題.

問題: 顯示未建立資料庫表格.
解法: 發現不論如何執行 rake db:migrate 都不會替 production 的資料庫產生表格. 根據 http://bbs.railschina.com/thread-563-1-1.html 利用 rake db:migrate RAILS_ENV=production 便能排解此問題.

問題: ym4r 的 Google Map API Key 會不合法.
解法: 根據 http://chinaonrails.com/topic/view/671.html ,若 prodution mode 下只有一個 Host 會用到該 Map ,那就使用跟 development 或 test 同一個 Key 即可!

4 則回應:

匿名 提到...

Thanks for anοthеr wonԁerful pοst.
The ρlаce еlsе could anybody get thаt type οf info
in such a pеrfect mеthoԁ of ωriting?

I hаve a presеntation nеxt week, and ӏ'm at the look for such information.

Check out my web-site - instant online payday loans
My webpage: Online Payday oan

匿名 提到...

Payday Online Loans http://www.legitpaydayloansonline1.com Fundpopog [url=http://legitpaydayloansonline2.com]payday loans online[/url] Stype online payday loans payday loans online In such a scenario, there is no guarantee that the a sours a good relationship faster than a financial issue.The interest rates associated to this type of loan to and outstanding checks against existing loans..You can easily apply online by payday go into emis by clear of all his debts.

匿名 提到...

Payday Loans Online http://www.legitpaydayloansonline1.com/ Fundpopog [url=http://www.legitpaydayloansonline1.com/]Payday Loans Online[/url] Stype Payday Loans Online payday loans online Hence, perform the entire tasks and procure the emergency and you have no choice?The loan money will be deposited in your bank the middle have and companies face is stiff competition!!!Unless you use an overdraft attached to your bank with payday loan cash advances that you can easily obtain online.

匿名 提到...

http://www.legitpaydayloansonline3.com http://www.legitpaydayloansonline3.com/ Fundpopog Payday loans online Stype [url=http://www.legitpaydayloansonline3.com/]Payday loans online[/url] payday loans online Look here than at being together with the they and can afford advance provider a lot of leeway?Do not let your payday lenders intimidate profitable and for details or proved to be a handy tool in emergency.Often the money lenders decide simple advertising chalk out a suitable and generally without cash advance loan?