Rails / On Dreamhost
From WhyNotWiki
Contents |
[edit] Install RubyGems locally
Gems / How to install to your home directory
[edit] Create Rails app
[edit] Change .htaccess
public/.htaccess:
From:
RewriteRule ^(.*)$ dispatch.cgi [QSA,L]
To:
RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]
[edit] Database
> gem install sqlite3-ruby Select which gem to install for your platform (i386-linux) 1. sqlite3-ruby 1.2.1 (mswin32) 2. sqlite3-ruby 1.2.1 (ruby) 3. sqlite3-ruby 1.2.0 (mswin32) 4. sqlite3-ruby 1.2.0 (ruby) 5. Skip this gem 6. Cancel installation > 2
[edit] Will want to run in development environment, unless you change it
I believe that the production web server (served via FastCGI in the case of Dreamhost) should always use the production environment/database.
config/environment.rb:
# We *only* want it to user the production environment if it's set that way in the environment or if this is being dispatched # from FastCGI (which only happens for the production server; the development server uses Webrick or other means). ENV['RAILS_ENV'] ||= 'production' if caller.last =~ /dispatch\.f?cgi/
As far as development goes... At least during the first couple of iterations, when it's only me that is using it, I don't see much point in using the development environment at all, so sometimes I skip to just developing under the production environment...
> export RAILS_ENV=production > rake db:migrate
[edit] Does it restart automatically? How often?
Well, it will start automatically the first time you request the page. In other words, it will start automatically if it's not already started.
However, once it's running, I'm not sure if ever restarts itself. (Maybe it will because Dreamhost's watchdog will kill it occasionally?)
If you really wanted to find out how often it restarted, you could add some logging to config/environment.rb. Something like this perhaps...
File.open('.../log/restart.log', 'a') {|file|
file.puts '----------------------------'
file.puts Time.now.to_s
#file.puts ENV.inspect
file.puts caller
}
(Or maybe it would make more sense to put it straight in public/dispatch.fcgi...)
In any case, if you notice that it doesn't seem to be running with your latest code, you will need to manually restart it, as described in the next section...
[edit] How to restart
To see what processes are running currently and when they were last (re)started:
> /bin/ps ux | grep '/usr/bin/ruby1.8 dispatch.fcgi'
\/ when they were last (re)started
tylerri 13955 0.3 0.8 38772 33992 ? S 17:26 0:04 /usr/bin/ruby1.8 dispatch.fcgi
tylerri 21335 0.0 0.8 38772 33992 ? S 17:26 0:00 /usr/bin/ruby1.8 dispatch.fcgi
tylerri 9746 0.0 0.8 38772 33992 ? S 17:26 0:00 /usr/bin/ruby1.8 dispatch.fcgi
To restart:
> killall -USR1 dispatch.fcgi > /bin/ps ux | grep '/usr/bin/ruby1.8 dispatch.fcgi' tylerri 31257 42.5 0.4 22900 20296 ? D 17:49 0:00 /usr/bin/ruby1.8 dispatch.fcgi
[edit] Links
http://wiki.dreamhost.com/Rails
[edit] Old links
http://www.railshosting.org/#dreamhost Ruby on Rails Hosting § Rails Hosting Reviews, Tutorials, Demos, and More...
http://gizmoojo.wordpress.com/2006/02/28/6-tips-for-deploying-ruby-on-rails-with-dreamhost/ 6 tips for deploying Ruby on Rails with Dreamhost « Gizmoojo!
http://casperfabricius.com/blog/2006/05/21/rails-on-dreamhost/ Fingerprints of Casper Fabricius » Deploying Rails with Edge and Engines to Dreamhost using Capistrano
http://woss.name/2006/01/22/using-switchtower-with-ruby-on-rails-and-dreamhost/ Howto: Using Switchtower with Ruby on Rails and DreamHost at Notes from a messy desk
