Application Error - Rails application failed to start properly

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.

Get your Rails app working

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

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 latest stable version)

svn co -r 997 http://dev.rubyonrails.org/svn/rails/trunk
# (insert revision number you want instead of 997)

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 "<h2>Application error</h2>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.

  • Ryan said: $ chmod -R 666 log Makes the log directory unaccessible, is that what you wanted?
  • Danger said: 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.
  • Jeff said: 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.
  • Danger said: Thanks for that Jeff, I'll add that to the list - it's a big help!
  • MH said: 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.
  • Clayton said: 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.
  • Clayton said: 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/
  • John said: Thanks so much for this..... I did the first few steps. I just wish I could get the last day back.....
  • Geoff said: Thank you so much... You save what's left of my night. Everything seems to work now. I'm definitely bookmarking your site. CU
  • Yet another Jeff said: 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.
  • Adam Roth said: 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.
  • random8r said: 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.
  • dan said: 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.
  • dan said: 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.
  • Gustavo said: 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?
  • Danger said: 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.
  • Evgeniy said: 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.
  • prash said: 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.
  • Danger said: Congratulations on getting it working prash. You know, I keep having to refer to this page myself :-)
  • sanjeev said: 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... :-(
  • Marcin said: Cheers! Lost nearly two days before found this one. Great help!
  • Nick said: Thanks! Not sure which one worked, think it was some logs permissions in the end. Either way - good work..
  • Dayne said: I also had an issue with puts in my Helper code. Thanks to whoever pointed that out. Saved me a headache.
  • j2ibeo said: I am having the Rails application failed to start properly error in Windows environment and XAMPP. Anybody successful on these combo?
  • Josh said: There is a broken link in your article. I think this is the new URL: http://6brand.com/my-dispatch-fcgi
  • Jack Danger said: Thanks for catching that Josh! The switch from Typo to Mephisto caused a lot of issues like that...
  • Developer said: 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!
  • Timo K. said: Thanks a lot for posting this. Has helped me an aweful lot. Cheers!
  • Roger said: 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!
  • Sean said: Thank you so much for sleuthing the .htaccess issues affecting FastCGI. You saved me hours!
  • Octavio said: I've been trying all the options here and nothing, I have 2 days in this :( any other ideas? thank you
  • Jack Danger said: 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?
  • manish said: 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.
  • Jim said: 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
  • Jason said: Very good article which will be a great help to visitors thank you
  • Jonathan said: I hope there is a special place in heaven for people who write things that are this useful. Wish I'd found it earlier! Thanks for posting this.
  • Chris said: Thanks a lot for these information - normally it is only coming when the site is on the server - locally it is ok ... maybe I will check again...
  • francisco said: this worked perfectly. I was missing the "dispatch.cgi" execute permissions. How dumb!!!
  • Slawek said: I new to rails, company decided to try it on. I installed newest RoR on FC5 server (apache 2.2). I managed get to work Redmine (ruby application) with Webrick. But I want to host it on apache 2.2. I did managed to make it work wit mod_cgi but it is very slow. I cannot make it work with mod_fastcgi. in my httpd.cong SetEnv RAILS_ENV production ServerName ruby.mydomain.pl DocumentRoot /usr/java/redmine-0.7/public AllowOverride all Order allow,deny Allow from all ErrorLog /var/log/httpd/error/ruby.mydomain.pl.error_log CustomLog /var/log/httpd/ruby.mydomain.pl.log combined env=!image default /usr/java/redmine-0.7/public/.htaccess privided by redmine: AddHandler fastcgi-script .fcgi AddHandler fcgid-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] RewriteRule ^(.)$ dispatch.fcgi [QSA,L] ErrorDocument 500 “ Application error Rails application failed to start p roperly” When I run application from browser: http://ruby.mydomain.com/ ” Application error Rails application failed to start properly ” There is nothing in production.log in apache log: Thu Jun 05 17:56:26 2008 [client 79.189.62.210] Request exceeded the l imit of 10 internal redirects due to probable configuration error. Use ‘LimitInt ernalRecursion’ to increase the limit if necessary. Use ‘LogLevel debug’ to get a backtrace. envioronment.rb is set for production when: http://ruby.mydomainn.pl/picture.jpg (which I have uploaded to /public directory I’m getting the some error. when uncommented in httpd.conf #LoadModule fastcgi_module modules/mod_fastcgi.so I can see the picture with dispatch.cgi I can see redmine working with mod_cgi. Regards I would appreciate any help. I have already spent 2 days trying to figure it out. Regards Slawek
  • Adam said: Just another happy developer leaving you a note to thank you all for the free advice. This was the final roadblock... so I set permissions, removed any mention of puts, and voila, successful migration to apache-mongrel-capistrano-etc.. :)
  • Adam A. said: i have a strange one....my app is up and running for the most part. it will serve up pages fine and well, except for one particular instance...but then, the error it gives is 'Rails App failed to start properly,' but i know the app is running already because other pages work. the weirder thing (and hopefully a clue) is that the page in question takes a text input from a previous page and WORKS IF THE INPUT IS SHORT but FAILS IF THE INPUT IS LONG. somewhere between 16 and 20 characters.... it was working before with inputs of any length. i changed nothing. and now it's gone mad. i'm very confused.
  • Adam A. said: Forgot to mention, the problem page is the 'reader', or the page you are taken to after you give some input text on 'http://www.thechinesereader.com/xiaolongbao/pinyinize' thanks for any help you can offer.
  • Michael Web said: Thanks a lot for posting this, it helped me a lot.
  • Herbalife said: Doesn´t work (??)
  • Suchmaschinenoptimierung said: I think the thread is old and the codes are maybe not actual anymore...
  • Colostrum said: Ok I tried it and it worked. But it´s not for dummies! :)
  • LR Kosmetik said: It ´s working you should try again. Quite nice.
  • Samir Jajjawi said: This is a great resource, its working!
  • SEO Beratung said: It's really working...
  • Baugeld said: I think it depends on the version!
  • schmuck said: maybe it depends on the browser. Try it again with a different browser.
  • Haustüren said: @ Schmuck: what the hell are you writing?
  • Detektei said: $ chmod -R 775 tmp ? Not 777?
  • Daniel said: Thank you for this. It helped me to find a solution to some of my problems.
  • DDDepressionnn said: There has come winter :( It became cold and cloudy! Mood very bad :( Depression Begins
  • Dieseltuning said: It depends whether on the version nor on the browser - it is working
  • DDDDepressionnnn said: Depression Depression Depression aaaaaaaa HEEEEELP :( :( :( I hate winter! I want summer!
  • Detektei said: @ Depression: me too :)
  • Matratze said: This guide really helps me a lot. Thanks for publishing it!
  • Babytrage said: @Detektei: if you put it on 777 you change the files from outside! It´s not recommanded!
blog comments powered by Disqus