我們會需要將 rails 與 apache 整合...你總不會想要用 port 3000 來提供服務吧...
安裝程序:引用:
# gem install passenger
# yum install curl-devel httpd-devel
# passenger-install-apache2-module
安裝完之後...需要到 /etc/httpd/conf/httpd.conf 最後面加上這幾行
引用:
LoadModule passenger_module /usr/local/rvm/gems/ruby-2.1.3/gems/passenger-4.0.53/buildout/apache2/mod_passenger.so
<IfModule mod_passenger.c>
PassengerRoot /usr/local/rvm/gems/ruby-2.1.3/gems/passenger-4.0.53
PassengerDefaultRuby /usr/local/rvm/gems/ruby-2.1.3/wrappers/ruby
</IfModule>
最後實做一個 Rails Example:
先安裝 sqlite .暫時使用文字型的資料庫
# yum install sqlite-devel
# cd /var/www/html
再來建一個 helloapp 的rails 資料匣:
# rails new helloapp
# cd helloapp
之後會產生很多檔案...在根目錄裡找到一支 Gemfile
在檔案最後面加上 :
然後執行:
# bundle install
# rake db:migrate
最後設定Apache的 virtual host 如下面的範例:
RackEnv development 必加...別忘了!引用:
RackEnv development
<VirtualHost *:80>
ServerName ror.adj.com.tw
# !!! Be sure to point DocumentRoot to 'public'!
DocumentRoot /var/www/html/helloapp/public
<Directory /var/www/html/helloapp/public>
# This relaxes Apache security settings.
AllowOverride all
# MultiViews must be turned off.
Options -MultiViews
</Directory>
</VirtualHost>
重啟 Apache:
# service httpd restart
這樣就完成 VirtualHost 的設定囉~
參考資料:
https://www.digitalocean.com/community/tutorials/how-to-setup-a-rails-4-app-with-apache-and-passenger-on-centos-6