Rails FedoraCore4 で動かす(1)

Rubyのインストール

  • su してコンソールから以下を打って確認するが,Fedora Core4 にはRubyはやっぱり入ってない.

ruby -v

  • とりあえず一つずつ実行

yum install ruby
yum install ruby-devel
yum install rdoc
yum install irb


Installed: ruby.i386 0:1.8.4-3.fc4
Dependency Installed: ruby-libs.i386 0:1.8.4-3.fc4
Complete!

RubyGemsのインストール

tar -xvzf rubygems-0.9.2.gz
cd rubygems-0.9.2


ruby setup.rb config
ruby setup.rb setup
ruby setup.rb install

  • FC5以降なら,yumでいける 2007/12/28 追記

yum install rubygems

Railsのインストール

-- version 1.2.1 とかできるらしい

gem install rails --include-dependencies


Bulk updating Gem source index for: http://gems.rubyforge.org
Successfully installed rails-1.2.2
Successfully installed rake-0.7.1
Successfully installed activesupport-1.4.1
Successfully installed activerecord-1.15.2
Successfully installed actionpack-1.13.2
Successfully installed actionmailer-1.3.2
Successfully installed actionwebservice-1.2.2
Installing ri documentation for rake-0.7.1...

WEBrickサーバ起動

  • root から一般ユーザに戻り,Railsプロジェクト test を作成してみる
  • [~xxx/public_html/rails]を作成

rails test
cd test
ruby script/server


=> Booting WEBrick...
=> Rails application started on http://0.0.0.0:3000
=> Ctrl-C to shutdown server; call with --help for options
[2007-02-20 21:03:33] INFO WEBrick 1.3.1
[2007-02-20 21:03:33] INFO ruby 1.8.4 (2005-12-24) [i386-linux]
[2007-02-20 21:03:33] INFO WEBrick::HTTPServer#start: pid=26535 port=3000

Hello表示アプリで動確

  • コントローラ Say 作成

ruby script/generate controller Say

  • アクション hello 作成(/app/controllers/say_controller.rb)
class SayController < ApplicationController
  def hello
  end
end
  • ビュー 作成
<html>
  <head>
    <title>Rails!</title>
  </head>
  <body>
  <h1> Helloooooo!! </h1>
  </body>
</html>

Apache で生CGIとしてまず動かす

  • 先ほどまでのWEBrickサーバをとめる(Ctrl-c)
  • Apache 2.0系はインストール済み
  • WEBrick でのキャッシュなどをクリア

rake tmp:clear

  • RAILS_ROOT/public/.htaccess は以下が記載されていること確認して,そのまま.

AddHandler fastcgi-script .fcgi
AddHandler cgi-script .cgi
Options +FollowSymLinks +ExecCGI


RewriteEngine On
RewriteRule ^$ index.html [QSA]
RewriteRule ^([^.]+)$ $1.html [QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ dispatch.cgi [QSA,L]

  • /etc/httpd/conf/httpd.conf の最終行に以下を追加


SetEnv RAILS_ENV development
ServerName XX.XX.XX.XX
DocumentRoot /home/xxx/public_html/rails/test/public/
ErrorLog /home/xxx/public_html/rails/test/log/server.log

Options ExecCGI FollowSymLinks
AllowOverride all
Allow from all
Order allow,deny

chmod 755 /public/dispatch.cgi dispatch.fcgi dispatch.rb

  • log/development.log をみると,/tmp/sessions で Permission deniedになっている.Apacheの書き込みだった.(←結構はまった)

chmode 777 sessions

  • で動いたけど…う〜ん.とりあえずはこのまま.
  • http://XX.XX.XX.XX/say/helloRailsApache + 生CGI で動いた.うわさ通り,ローカルで使うにしてもこれは遅すぎる.
  • development環境からproduction環境にしてみるけど相変わらず遅い
  • 次はFastCGIかな.