6 tips for deploying Ruby on Rails with Dreamhost

February 28, 2006 at 5:41 am | In Ruby on Rails, dreamhost, gizmoojo, rails | 22 Comments

I just feel that I have to blog about this since I spent more than the amount of time and effort to get Gizmoojo’s alpha signup page going with our webhosting, Dreamhost. With the amount of time that I spent googling and reading forums and blogs about the trouble they had, I think this post would be an excellent resource for aynone that is facing any problems who spent “9hrs developing an 48hr deploying”.

1) Avoid using a sub-directory for your rails application if ever possible
One huge pain that I had was setting the rails app as a sub-directory. If you had read the Rail wiki at dreamhost, Rails always runs at the top level of a domain. So for example, in my case, I have setup a full hosting service on the dreamhost server for gizmoojo.com. So to setup rails, all you have to do is something like “rails www.gizmoojo.com” and that will setup the rails app in the webdoc root. So now, all you need to do is insert a symbolic link using “ln -s www.gizmoojo.com/public public” and then remap the root to point to “public”. So instead of having to go to www.gizmoojo.com/railsapp/, you have the railsapp setup as where www.gizmoojo.com -> www.gizmoojo.com/public” and “public” is a symbolic link to /home/user/url/www.gizmoojo.com/public.

2) Read the Dreamhost Wiki patiently.
One thing that I know is that if you have followed exactly what the Dreamhost’s wiki for setting up Rails, you will have good chance of getting it to work on first shot. No I just took a quick glimpse of the rails wiki on dreamhost and off I go. And without a doubt I had a “Rails Application Error” when I fired up my firefox and pointed to www.gizmoojo.com.

3) Read this post in additional to the Dreamhost Wiki.

4) Setting up your config/database.yml
If you did a “rails xxxx”, all is you is the default config file with everything. So in the database.yml you will see development db setting, test settings and production settings for MySQL, PostGre and SQLite. So what I had was some default settings with my other settings as in a huge mess. So the problem I had was somewhere in database.yml I had 2 instances of settings for development. So clear out everything and make sure you only have production, test, and development like this:

production:
adapter: mysql
database: dbname
username: username
password: password
host: yourdb.gizmoojo.com*

* What you set it up in your dreamhost panel. Do not use localhost.
Now REMEMBER TO REMOVE THE http sock statement and the port # (you only need the port # if you are using SQLite)

5) FastCGI and other changes for the following:

  1. Your public/.htaccess file
    Modify all instances of dispatch.cgi in the railsapp/public/.htaccess file to dispatch.fcgi. In the current version of rails, there is only one line to change, on line 32:From:
    RewriteRule ^(.*)$ dispatch.cgi [QSA,L]
    To:
    RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]
  2. Your public/dispatch.fcgi
    After require 'fcgi_handler', change the rest of dispatch.fcgi to read:

    class MyRailsFCGIHandler  :exit_now,
    }
    
    def exit_now_handler(signal)
    dispatcher_log :info, "ignoring request to terminate immediately"
    end
    end
    
    MyRailsFCGIHandler.process! nil, 50
  3. Your config/environment.rb
    RAILS_ENV = ‘production’
  4. Your config/routes.rb
    To include any default controller if you had one
    map.connect ”, :controller => “example”

6. Use lower cases for your controllers
Try to use all lower case names for your controller files. “users_controller.rb” rather “Users_controller.rb” and also for your requires.

7. And last but not least.

Run dispatch.fgci in your railsapp/public directory and if all is well, you should get a 500 Error. And if there is something unhappy, you will be able to see some error messages there. And good luck!

Blog at WordPress.com. | Theme: Pool by Borja Fernandez.
Entries and comments feeds.