查看完整版本: 如何整合 Ruby on Rails (RoR) With Apache and Passenger on CentOS 6


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>這時就需要透過 &nbsp;apache 的&nbsp;Passenger module</div><div>安裝&nbsp;<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>&nbsp;&nbsp; LoadModule passenger_module /usr/local/rvm/gems/ruby-2.1.3/gems/passenger-4.0.53/buildout/apache2/mod_passenger.so<br>&nbsp;&nbsp; &lt;IfModule mod_passenger.c&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp; PassengerRoot /usr/local/rvm/gems/ruby-2.1.3/gems/passenger-4.0.53<br>&nbsp;&nbsp;&nbsp;&nbsp; PassengerDefaultRuby /usr/local/rvm/gems/ruby-2.1.3/wrappers/ruby<br>&nbsp;&nbsp; &lt;/IfModule&gt;<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>&lt;VirtualHost *:80&gt; <br>&nbsp;ServerName ror.adj.com.tw <br><font color="DarkRed">&nbsp;<br># !!! Be sure to point DocumentRoot to 'public'! </font><br>&nbsp;DocumentRoot /var/www/html/helloapp/public <br><br>&nbsp;&lt;Directory /var/www/html/helloapp/public&gt; <br>&nbsp;# This relaxes Apache security settings. <br>&nbsp;AllowOverride all <br>&nbsp;# MultiViews must be turned off. <br>&nbsp;Options -MultiViews <br>&nbsp;&lt;/Directory&gt; <br>&lt;/VirtualHost&gt; <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>
頁: [1]
查看完整版本: 如何整合 Ruby on Rails (RoR) With Apache and Passenger on CentOS 6