2009年8月11日火曜日

sakuraにrailsを入れる

rails2.3.3 だとpublic/dispatch.cgiが作成されないようなので、rails2.2.2で行います。
rails2.3.3をインストールしちゃったので、一旦アンインストールして
2.2.2をインストール
gem uninstall rails
gem install rails --version 2.2.2

railsアプリ用のディレクトリを作成。
  1. mkdir rails-apl  


rails-aplにrailsを生成する。
  1. cd rails-apl  
  2. rails todo -d mysql  


config/environment.rbを設定。
↓を追加
  1. # Be sure to restart your server when you modify this file  
  2. $LOAD_PATH.push("/home/XXX/lib/")  
  3. $LOAD_PATH.push("/home/XXX/lib/ruby")  
  4. ENV['GEM_HOME'] ||= '/home/XXX/lib/ruby/gem'  
  5. ENV['RAILS_RELATIVE_URL_ROOT']="/todo"  

さらに↓を追加
  1. # config.gem "aws-s3", :lib => "aws/s3"  
  2. nfig.gem "mysql":version => "2.7"  


public/.htaccessを設定と思ってたら、
生成されてないのでREADMEの
「== Apache .htaccess example for FCGI/CGI」部分をコピって
.htaccessをpublic/に作成。
その後、以下のように修正。
  1. # General Apache options  
  2. #AddHandler fastcgi-script .fcgi  
  3. #AddHandler cgi-script .cgi  
  4. #Options +FollowSymLinks +ExecCGI  
  5.   
  6. # If you don't want Rails to look in certain directories,  
  7. # use the following rewrite rules so that Apache won't rewrite certain requests  
  8. #  
  9. # Example:  
  10. #   RewriteCond %{REQUEST_URI} ^/notrails.*  
  11. #   RewriteRule .* - [L]  
  12.   
  13. # Redirect all requests not available on the filesystem to Rails  
  14. # By default the cgi dispatcher is used which is very slow  
  15. #  
  16. # For better performance replace the dispatcher with the fastcgi one  
  17. #  
  18. # Example:  
  19. #   RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]  
  20. RewriteEngine On  
  21.   
  22. # If your Rails application is accessed via an Alias directive,  
  23. # then you MUST also set the RewriteBase in this htaccess file.  
  24. #  
  25. # Example:  
  26. #   Alias /myrailsapp /path/to/myrailsapp/public  
  27. #   RewriteBase /myrailsapp  
  28.   
  29. RewriteRule ^$ index.html [QSA]  
  30. RewriteRule ^([^.]+)$ $1.html [QSA]  
  31. RewriteCond %{REQUEST_FILENAME} !-f  
  32. RewriteRule ^(.*)$ dispatch.cgi [QSA,L]  
  33.   
  34. # In case Rails experiences terminal errors  
  35. # Instead of displaying this message you can supply a file here which will be rendered instead  
  36. #  
  37. # Example:  
  38. #   ErrorDocument 500 /500.html  
  39. ErrorDocument 500 "<h2>Application error</h2>Rails application failed to start properly"  


改行に気をつける。。。

tmpとlogのパーミッションを変更
  1. cd rails-apl/Todo  
  2. chmod -R o+w log tmp  
  3. ls -l  


config/database.ymlの設定
  1. development:  
  2.   adapter: mysql  
  3.   encoding: utf8  
  4.   database: xxxxx  
  5.   pool: 5  
  6.   username: xxxxx  
  7.   password: password  
  8.   host: mysqlXX.db.sakura.ne.jp  


シンボリックリンクを張る
  1. ln -s $HOME/rails-apl/todo/public $HOME/www/todo  


これで、http://xxxxx.sakura.ne.jp/Todo/にアクセスすると
「Welcome aboard」が出てればOK♪
そこで「About your application’s environment」をクリック!



↓ランキング参加中!ポチッとお願いします。
ブログランキング・にほんブログ村へ人気ブログランキングへ

0 件のコメント:

コメントを投稿