Troubleshooting a Ruby on Rails Application
From OCS Support Wiki
Contents |
Introduction
This guide will walk you through the steps of diagnosing and fixing most common problems with Ruby on Rails applications that won't start.
About Your Production Log
Most useful diagnostic information about errors can be gleaned from your production log. To view it in real time, run (via SSH):
cd ~/rails_apps/yourapp tail log/production.log -f
Replace the path to your Rails app on the first line as needed. This will show you any errors in real time (you can go to your website to trigger one possibly). This will not work if your site isn't up.
You can use tail log/production.log -n 100 to see the last 100 lines of your log. Replace 100 with whatever number you want.
Testing a Standalone Mongrel
If your Rails application won't start, starting a stand-alone production Mongrel without sending it to the background is a great way to see if your application can start or not, and if not, typically the error will be displayed on the screen. To use this method, run:
cd ~/rails_apps/yourapp mongrel_rails start -e production -p 60000
Replace 60000 with your port number. If you don't have a port number (i.e. you use mod_rails / Passenger or CGI/FastCGI), you can temporarily use port 3000 as long as you close the mongrel soon after you verify that it can start without error.
When starting Mongrel like this, it is not meant to stay up. Press CTRL+C to terminate it.
Any errors you get may be useful in tracking down the problem.
General Problems with All Hosting Methods
- Did you setup your database and enter its details in the
config/database.ymlfile? Remember that we only allow production mode, so please make sure that you have your database configuration set for that. - If you have a line called
socket:in yourconfig/database.ymlfile underproduction, remove it and ensure thathost: localhostis there. - Are you attempting to run in development mode when your
config/database.ymlfile is setup for production mode? - It is ALWAYS a good idea to freeze your Rails application. Please see Freezing_Rails and freeze Rails to your application before further troubleshooting.
- If you are getting database errors while migrating your data, try:
RAILS_ENV=production rake db:migrate
instead of simply rake db:migrate. This will force production mode.
- If your Rails application was working but stopped working, you may have problems due to a recent upgrade in Rails (specifically the 2.0 upgrade). If this is the case, please make sure that the line:
RAILS_GEM_VERSION = '1.2.6' unless defined? RAILS_GEM_VERSION
is present and not commented out in your config/environment.rb file. It should be near the top. You can also try version 1.1.6 instead of 1.2.6 if you are still getting the same error. Also, you may have to disable action_web_service. To do so, edit config/environment.rb and make sure the line:
config.frameworks -= [ :action_web_service ]
is uncommented. It may have the phrase :action_mailer in it too, and if it does, remove it if your Rails application sends e-mails.
- If you're getting an error about soap, please see this mailing list post. Essentially, the workaround is to add:
require 'rubygems' gem 'soap4r'
at the top of config/environment.rb.
Hosting Method Specific Troubleshooting
Passenger / mod_rails
If you're using Passenger, please check that:
- A symlink exists between your Rails application's
publicdirectory and your public_html folder. You can learn how to do this by referring to our article titled Deploying a Rails Application With Passenger. - Make sure that the
.htaccessfile in your Rails application'spublicfolder has no other content except the PassengerAppRoot line in it, and make sure this setting points to the correct folder of your Rails app.
Mongrel
If your Mongrel won't start, here are some things to check:
- If you get an error about port already in use, please run:
killall -9 mongrel_rails ruby ruby1.8
via SSH and try again. If that doesn't fix it, cPanel may have allocated the port incorrectly. If this is the case, simply create a new Rails application in cPanel and move (or redeploy) your application to the new location. This will give you a new port.
FastCGI
- The dispatch.fcgi or dispatch.cgi has an incorrect path to Ruby. This won't be the case if you used the
ocs-install-railsscript, but if you developed on another machine, please make sure the path is#!/usr/bin/rubyin all scripts that include a Ruby path at the top (including the dispatch scripts in public folder and the generators and other utilities in the script folder) - Make sure that the
dispatch.fcgianddispatch.cgiscripts have0755 (-rwxr-xr-x)permissions. - Make sure that the
publicdirectory has the permissions of755 (-rwxr-xr-x). - Make sure the sessions path is writeable. Run
chmod 777 tmp/sessionsin the Rails instance folder to see if that fixes the problem. If so, we recommend you switch your sessions to database-backed for extra security. - Make sure you are accessing the Rails app with a trailing / after the URL, like
yoursite.com/rails/instead ofyoursite.com/rails.
If the above does not solve the problem with your Ruby on Rails application, try running dispatch.cgi on the command line via SSH. You can do this by typing:
cd ~/rails_sites/yourapp/public ./dispatch.cgi
Replace yourapp with the name of your Rails instance.
Hopefully, you will get some valuable information as to what is going on.
If not, then check the log/development.log or log/production.log to see if there are any errors being produced.
If you can't solve it from that, please contact us.
