6 tips for deploying Ruby on Rails with Dreamhost
February 28, 2006 at 5:41 am | In Ruby on Rails, dreamhost, gizmoojo, rails | 18 CommentsI 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:
- Your public/.htaccess file
Modify all instances of dispatch.cgi in therailsapp/public/.htaccessfile 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] - Your public/dispatch.fcgi
Afterrequire '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
- Your config/environment.rb
RAILS_ENV = ‘production’ - 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!
18 Comments »
RSS feed for comments on this post. TrackBack URI
Leave a comment
Blog at WordPress.com. | Theme: Pool by Borja Fernandez.
Entries and comments feeds.
Thank you!
I switched to production mode with an app earlier today and stupidly didn’t specify the correct production db in database.yml – hence rails errored out.
I then changed my database.yml, uploaded and bang! it’s still not working. Great. I just spent nearly 2 hours in fastCGI and configuration hell trying to restart processes all over on dreamhost thinking that the production version of rails was caching the db config and still trying to connect using the information from the old database.yml.
All the while I simply needed to specify my host BENEATH the production settings in database.yml – this post helped me see the simple truth – the wood for the trees!
God I feel like such a moron
Perhapsa the default database.yml should be rewritten slightly to include an optional ‘host:’ setting beneath all 3 db configs – not just beneath the development one. Alert the Rails team!
Comment by Daniel — March 7, 2006 #
Cool.. glad that this post has helped you in some way.
Comment by gizmoojo — March 7, 2006 #
I’m betting it’s some kind of interference from WordPress, but my dispatch.fcgi keeps choking on “class MyRailsFCGIHandler :exit_now,” then that [to me] weird lone bracket on the next line.
Comment by RSL — April 8, 2006 #
Interessando, luogo abbastanza luminoso, penso +5
Comment by Giorgia Palmas — December 2, 2006 #
[...] El wiki de rubyonrails sobre Rutas Gizmoojo Seguramente muchos han escuchado que correr aplicaciones rails en hosting compartidos no es una muy buena idea… pero mi opinión al respecto que es para sitios con alto trafico (cientos de miles de visitas al dia). [...]
Pingback by Nicolás Orellana » Blog Archive » URLs bien diseñadas gracias a Rails — December 2, 2006 #
Another good article. I hate what a pain it is to get Rails apps up and running on Dreamhost. So much so that I put up a step by step guide on getting it running: http://omgsean.com/articles/2007/03/18/installing-ruby-on-rails-on-dreamhost
Comment by Sean — March 21, 2007 #
Interesting comments..
Comment by imparare — April 15, 2007 #
Hello, Your site is great. Regards, Valintino Guxxi
Comment by Anonymous — May 8, 2007 #
Well a few new coupons at http://www.dreamhost.com/r.cgi?175823.
WAIVER – Hosting at only $27.40 for an entire year. No setup fee.
10TH – Dreamhost 10th birthday celebration discount
6FORME – 6 free domain registration for life with any Dreamhost hosting plan
Comment by Steve — June 6, 2007 #
[...] http://gizmoojo.wordpress.com/2006/02/28/6-tips-for-deploying-ruby-on-rails-with-dreamhost/ Tags: ruby, rails, ror, dreamhost(del.icio.us history) [...]
Pingback by 6 tips for deploying Ruby on Rails with Dreamhost « Gizmoojo! — June 10, 2007 #
Informative site. Best wishes from California!0
Comment by Hanna — September 9, 2007 #
%0D%0A%0D%0A%0D%0A%0D%0A%0D%0A%0D%0AInformative+site.+Best+wishes+from+California%210
Comment by Hanna — September 9, 2007 #
Hi,
I’ve hosted my rails app in my domain that too in sub directory as you mentioned in first point not to use sub directory. so what if i use sub directory. then only when is say public it runs as you said. is there any chance of avoiding that?
regards,
Bala
Comment by Bala — December 23, 2007 #
I have done what u have told. But still i m facing the same problem. Link to my site is http://www.copychops.com/welcome/
Can u help me please. Its running nice in my localhost which is window. But what happen in the server that is out of control for me.
Please help me.
Comment by manish — March 20, 2008 #
Hi!,
Comment by name — September 1, 2008 #
Hello!,
Comment by name — September 1, 2008 #
Good day!,
Comment by name — September 1, 2008 #
ehh. attractive.
Comment by Irreria — May 23, 2009 #