Hoopla!

now with extra whiz-bang!

Hoopla!

Application Error - Rails application failed to start properly

April 09, 2006 · 35 comments

Okay, I wish I could write this now and then go back in time two days, read it, and save myself a lot of hassle. I spent a lot of time trying to debug a rails installation on a shared host and it could have been so much easier.

  1. Get your Rails app working
  1. step one
Set file permissions. Do it like so: ./public needs to be set to 755
$ chmod 755 public
./public/dispatch.fcgi (or dispatch.cgi – but don’t use that!) also to 755
$ chmod 755 public/dispatch.fcgi
make sure ./public/.htaccess exists (my copy can be found at the bottom of this post) ./log and everything under it needs to be set to 775
$ chmod -R 775 log
do the same for the ./tmp directory (Rails writes session data here)
$ chmod -R 775 tmp
#### step two Make sure you’re running in ‘development’ mode. Code errors will be displayed to the screen in this mode – but ‘production’ will just barf out on you (it’s intended to work this way). Set RAILS_ENV=’development’ in config/environment.rb if you have no other way to do this.
$ nano config/environment.rb
#### step three If the above didn’t work, look at the bottom of any of your log files. Depending what environment you’re in you may need development.log or production.log. If it gives you a handy error like ‘could not find environment.rb’ or something like that it’ll really help you figure out the problem.
$ tail -n 100 log/development.log
#### step four Get into the ruby console. Try to run a command like you would in your app like User.find_all or something similar. This will show you errors that wouln’t come up elsewhere.
$ ./script/console 
  1. step five If you’re running an app that requires a specific version of Rails but didn’t include it along with the app you’ll need to ‘freeze’ Rails into your app. This is actually quite simple – if you put the whole Rails source code into ./vendor/rails then your application will use that code instead of the stuff on your server at /usr/lib/ruby/ The way to do this is to run any of the following:
rake freeze_gems
(get the latest stable version)
rake freeze_edge
(get the cutting-edge version)
svn co -r 997 http://dev.rubyonrails.org/svn/rails/trunk
(insert revision number you want instead of 997)
  1. good luck!
### Resources: My working .htaccess file:

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.fcgi [QSA,L]

ErrorDocument 500 /500.html

#ErrorDocument 500 "

Application error

Rails application failed to start properly"

If these steps didn’t work for you leave a comment and I’ll try to help you out. I’m a GNU guy so I don’t know much about Rails on Windows, but I’d be happy to help you avaoid the hideous, hideous Rails errors.

Also, if you’re looking at random 500 errors while working on your Dreamhost account, you’ll want to use a modified dispatch.fcgi file.

Tags:·······

35 responses so far ↓

  • 1 Ryan // Jun 05, 2006 at 11:33 AM

    $ chmod -R 666 log Makes the log directory unaccessible, is that what you wanted?
  • 2 Danger // Jun 05, 2006 at 03:41 PM

    Wow, you're right. There's a huge difference between chmod 666 and chmod 0666. I'm making a change in the above post - thanks for the help! If you've got any other ideas, please share them - it's a bitch to try to get rid of rails-styled 500 errors.
  • 3 Jeff // Jun 10, 2006 at 03:00 PM

    In log/development.log it said something about not having permission to write to /tmp/sessions/ I'm not sure if this was a good idea but: chmod -R 0666 tmp ... fixed my issue. I followed your steps and still got the error, now I'm good to go.
  • 4 Danger // Jun 10, 2006 at 03:01 PM

    Thanks for that Jeff, I'll add that to the list - it's a big help!
  • 5 MH // Jun 21, 2006 at 08:01 PM

    For hours, I was trying to get rid of of my error 500. It turned out that the dispatch was okay (as on can find out by entering a "wrong" URL and looking at the error message). It was a simple "puts" statement that remained in the code from some debugging on my local computer. But is was this tiny statement that made my server to produce this error 500.
  • 6 Clayton // Jun 23, 2006 at 06:47 AM

    I've tried to setup RoR using Apache2, MySQL and Fcgid on FreeBSD. If I change RewriteRule ^(.*)$ dispatch.fcgi [QSA,L] To RewriteRule ^(.*)$ dispatch.cgi [QSA,L] I get the “Application Error - Rails app failed to start properly" message. If I use .fcgi as suggested I just get the contents of dispatch.fcgi when I try to access part of the app that does work if I use Webrick. I also get the contents of dispatch.fcgi when I click on the "About your Applications Environment" when I'm viewing the "Rails Welcome Aboard" page. I figured it was a matter with changing the shebang line to reflect the actuall location of ruby on my system, but that hasn't helped either.
  • 7 Clayton // Jun 23, 2006 at 07:35 AM

    Well I figured out the issue. In httpd.conf I had AddHandler fcgid-script .fcgi HOWEVER In the .htaccess I had AddHandler fastcgi-script .fcgi Because I'm using Apache2 I don't have fast_cgi installed so that's why it wasn't working. It finally dawned on me when reading: http://www.tummy.com/Community/Articles/rails-fcgi/
  • 8 John // Jul 19, 2006 at 12:47 PM

    Thanks so much for this..... I did the first few steps. I just wish I could get the last day back.....
  • 9 Geoff // Jul 27, 2006 at 09:01 AM

    Thank you so much... You save what's left of my night. Everything seems to work now. I'm definitely bookmarking your site. CU
  • 10 Yet another Jeff // Aug 07, 2006 at 06:38 AM

    One more that has caught me before. Sometimes ruby or env are installed at different locations which causes the shebang line to be wrong in the scripts. If you are deploying on a shared host, that's always another good thing to check.
  • 11 Adam Roth // Aug 07, 2006 at 07:12 AM

    Note, also make sure that your dispatch.fcgi is pointing to the right location of ruby. I had just moved a site to a new server with a different ruby location, and the app bombed as described above.
  • 12 random8r // Aug 14, 2006 at 02:04 AM

    I was having HEAPZ of problems like this... then i realised I hadn't killed all my ruby instances on my server, so it wasn't propagating the change of environment (it was working in dev, but switching to prod, it broke after a bit)... all is great now. YAY.
  • 13 dan // Aug 21, 2006 at 11:58 PM

    Thanks, this page was a huge help. My issue was a random puts in the controller. Odd that the logs say it is fine and show a 200 status. Seems like this might be a weak link.
  • 14 dan // Aug 21, 2006 at 11:58 PM

    Thanks, this page was a huge help. My issue was a random puts in the controller. Odd that the logs say it is fine and show a 200 status. Seems like this might be a weak link.
  • 15 Gustavo // Sep 01, 2006 at 11:51 AM

    I checked my production log but its empty. My dreamhost error log says this though: FastCGI: comm with (dynamic) server "/home/seventhdegree/your_directory/public/dispatch.fcgi" aborted: (first read) idle timeout (120 sec) FastCGI: incomplete headers (0 bytes) received from server "/home/seventhdegree/your_directory/public/dispatch.fcgi" what does this mean?
  • 16 Danger // Sep 02, 2006 at 05:37 AM

    It looks like your server's installation of FastCGI is either improperly configured or just not working well with your Rails app. I recommend replacing your dispatch.fcgi file with this one.
  • 17 Evgeniy // Sep 26, 2006 at 02:48 AM

    I mentioned that this error could rise if first line of your dispach files within public/ directory have wrong path to ruby binaries. It look like #!c:/ruby/bin/ruby by default. Check this with your installation path.
  • 18 prash // Feb 08, 2007 at 02:11 PM

    thank you! wish i could get the last 5 hours back. in my case it was "rake freeze_gems", or rather the new version "rake rails:freeze:gems", that did the trick) this page should be gold plated and linked to from the rails home page.
  • 19 Danger // Feb 17, 2007 at 09:45 AM

    Congratulations on getting it working prash. You know, I keep having to refer to this page myself :-)
  • 20 sanjeev // Jul 19, 2007 at 03:40 AM

    hey, I have a problem.. I have been discussion this problem out here "http://rubycorner.net/rails-programming/rails-and-rmagick-made-easy-generating-thumbnails/#comment-528" and created a new topic out here "http://forum.rubycorner.net/index.php/topic,12.0.html". I am gettign the same error and I followed all the steps except the fact that I could not execute the "chmod -R 0666 tmp" command as my server on ASO says "chmod: `tmp': Permission denied". Please help me out if you can look into the issue. Give me some hint I am fed up now... :-(
  • 21 Marcin // Aug 08, 2007 at 04:24 PM

    Cheers! Lost nearly two days before found this one. Great help!
  • 22 Nick // Aug 08, 2007 at 04:25 PM

    Thanks! Not sure which one worked, think it was some logs permissions in the end. Either way - good work..
  • 23 Dayne // Aug 12, 2007 at 06:12 AM

    I also had an issue with puts in my Helper code. Thanks to whoever pointed that out. Saved me a headache.

  • 24 j2ibeo // Oct 26, 2007 at 05:21 PM

    I am having the Rails application failed to start properly error in Windows environment and XAMPP. Anybody successful on these combo?

  • 25 Josh // Nov 12, 2007 at 08:24 PM

    There is a broken link in your article. I think this is the new URL: http://6brand.com/my-dispatch-fcgi

  • 26 Jack Danger // Nov 13, 2007 at 10:08 AM

    Thanks for catching that Josh!

    The switch from Typo to Mephisto caused a lot of issues like that…

  • 27 Developer // Nov 16, 2007 at 02:30 PM

    Thank you so much! I just spent a few hours trying to figure out the problem, and fixing the environment.rb file (as you suggested in step two) did the trick. Thank you thank you thank you!

  • 28 Timo K. // Jan 08, 2008 at 08:21 AM

    Thanks a lot for posting this. Has helped me an aweful lot. Cheers!

  • 29 Roger // Jan 15, 2008 at 06:36 PM

    with mine cgi worked fine, but fastcgi didn’t—turned out that (one bluehost, at least) they had upgraded, and I needed to change it to AddHandler fcgid-script .fcgi at the top of dispatch.fcgi. Thanks bluehost!

  • 30 Sean // Mar 04, 2008 at 12:51 PM

    Thank you so much for sleuthing the .htaccess issues affecting FastCGI. You saved me hours!

  • 31 Octavio // Mar 06, 2008 at 03:29 PM

    I’ve been trying all the options here and nothing, I have 2 days in this :( any other ideas?

    thank you

  • 32 Jack Danger // Mar 08, 2008 at 01:08 PM

    Octavio: It all depends on what error you’re seeing. Is there anything in the log file? Does the app run on one computer and not another? What happens when you try to get into the console?

  • 33 manish // Mar 21, 2008 at 12:20 AM

    I have done all the things which u have said but still error is coming. My dispatch.fcgi is running good in my localhost but when i run it in the server it shows the error.

  • 34 Jim // Apr 22, 2008 at 04:24 AM

    Hi. Wish i’d found this page about a fortnight ago when i was trying to debug the “Application error Rails application failed to start properly” error page. Production logs showed nothing unusual. It had me proper stumped…. Until the tech support at my hosting compnay pointed out that using puts in your code can cause problems with Apache and i had a ton of them left in from development…... DOH! Bookmarking this for future (headache saving) reference. Thanks

  • 35 Jason // May 08, 2008 at 03:46 PM

    Very good article which will be a great help to visitors thank you

Leave a Comment