apple 2014-10-20 17:04
如何整合 Ruby on Rails (RoR) With Apache and Passenger on CentOS 6
在安裝完 ruby on rails 之後...參考這篇教學:<div><a href="http://dz.adj.idv.tw/thread-149266-1-1.html" target="_blank">在 CentOS 6.x 上透過 RVM 快速安裝 Ruby on Rails ( RoR )</a></div><div><br></div><div>我們會需要將 rails 與 apache 整合...你總不會想要用 port 3000 來提供服務吧...</div><div>這時就需要透過 apache 的 Passenger module</div><div>安裝 <span style="line-height: 1.6em;">Passenger 最少需要 1 GB 的 RAM</span></div><div><br><font size="3" color="DarkGreen">安裝程序:</font><br>[quote]<br># gem install passenger <br># yum install curl-devel httpd-devel <br># passenger-install-apache2-module<br>[/quote]<br><br>安裝完之後...需要到 /etc/httpd/conf/httpd.conf 最後面加上這幾行<br>[quote]<br> LoadModule passenger_module /usr/local/rvm/gems/ruby-2.1.3/gems/passenger-4.0.53/buildout/apache2/mod_passenger.so<br> <IfModule mod_passenger.c><br> PassengerRoot /usr/local/rvm/gems/ruby-2.1.3/gems/passenger-4.0.53<br> PassengerDefaultRuby /usr/local/rvm/gems/ruby-2.1.3/wrappers/ruby<br> </IfModule><br>[/quote]<br><br>最後實做一個 Rails Example:<br><br>先安裝 sqlite .暫時使用文字型的資料庫<br><br># yum install sqlite-devel <br># cd /var/www/html <br><br>再來建一個 helloapp 的rails 資料匣:<br><br># rails new helloapp <br># cd helloapp <br><br>之後會產生很多檔案...在根目錄裡找到一支 Gemfile<br>在檔案最後面加上 :<br><br>[quote]<br>gem 'therubyracer' <br>[/quote]<br><br>然後執行:<br><br># bundle install <br># rake db:migrate <br><br>最後設定Apache的 virtual host 如下面的範例:<br><font color="Blue">RackEnv development 必加...別忘了!</font><br><br>[quote]<br><font color="Red">RackEnv development</font><br><br><VirtualHost *:80> <br> ServerName ror.adj.com.tw <br><font color="DarkRed"> <br># !!! Be sure to point DocumentRoot to 'public'! </font><br> DocumentRoot /var/www/html/helloapp/public <br><br> <Directory /var/www/html/helloapp/public> <br> # This relaxes Apache security settings. <br> AllowOverride all <br> # MultiViews must be turned off. <br> Options -MultiViews <br> </Directory> <br></VirtualHost> <br><br>[/quote]<br><br>重啟 Apache:<br># service httpd restart <br><br>這樣就完成 VirtualHost 的設定囉~<br><br>參考資料:<br>https://www.digitalocean.com/community/tutorials/how-to-setup-a-rails-4-app-with-apache-and-passenger-on-centos-6<br></div>