"; */ ?>

Deploy Rails Application on Bluehost

Rails on Bluehost
Deploying Rails application on Bluehost for the first time can be quite frustrating. Bluehost provides 24/7 support via phone, ticketing system and live chat, which could seem appealing at first. However people with knowledge of Rails (and quite frankly simple networking/hosting) is a pretty rare find at Bluehost.

Forget phone and live chat support when it comes to Rails – it is not there – period. Ticketing support has a “24 hour come back” policy and most of the time the answer would be “read documentation in bluehost knowledge database”. And it would be ok (not good, but still ok) if bluehost knowledge database had any useful information – it does not.

The problem being is that bluehost, as any other hosting company, has its own proprietary configuration, and it is fine, but without the supporting documentation, bluehost is just an unusable black box. Hence friendly hacking is the only way to go to open it.

Choosing a Rails host today, I would definitely give a try to hostingrails, site5 or asmallorange, but some of my clients are with Bluehost, and since I like solving problems, here is a solution on how to deploy your Rails application to Bluehost.

Firstly, you would need to have an “SSH/Shell Access” enabled on your bluehost account. This requires you to show your “government issued photo id” (driver license / passport / state id / etc..) to Bluehost support. You can do it either through the ticketing system (upload along with the ticket), or while on the phone, you can upload it to one of your directories (e.g “tmp”) via cPanel, so they can look at it immediately, and activate your SSH access.

Once the access is granted/activated, you can ssh to your domain through cPanel Java Applet:

 Security -> 'SSH/Shell Access' -> 'Connect using SSHTerm (requires Java)'

However the applet will only work on Windows box (at least not via Ubuntu / Mac). Therefore it is much easier to just ssh to your domain from a command line:

user@host:$ ssh yourusername@youdomain.com

‘username’ can be found on the left hand side of the main cPanel view. Password is the same as for your bluehost account.

Now it is time to get to work, and deploy your Rails application.

Before hitting the terminal and work via command line, there are two more things that need to be done via cPanel:

1. Upload your application to the bluehost box. From cPanel main view:

 Files -> 'Unlimited FTP' -> 'UnlimitedFTP' button

That loads a simple FTP Java app inside your browser (this one works on Mac / Ubuntu :) ) with a regular left/right pannel, where you can select you Rails application on your local box (panel on the left), and drag and drop it in a directiry (e.g. “tmp”) to the bluehost box (panel on the right).

2. Create a subdomain by going to cPanel main view:

 Domains -> 'Subdomains', enter "dumbapp" (no quotes) to Subdomain' field, and click 'Create' button

There is no real need to create this subdomain (unless you really need a subdomain), but it will come handy later on for testing, and such.

Now let’s hit that command line… SSH to your box (ssh bluehostusername@yourdomain.com)

3. Go to your home directory (just in case), and create a “dumbapp” rails application:

cd ~
mkdir rails
 
cd rails
rails dumpapp

4. Now you are in “~/rails” directory, copy YOUR real application to it:

cp -r path-where-your-rails-app-is-uploaded/your-rails-app-name .

5. Copy dispatch.* files from the “dumbapp” to YOUR real application:

cp dumpapp/public/dispatch* your-rails-app-name/public

6. Goto “~/public_html”, and create a symbolic link to YOUR application’s public directory

cd ~/public_html
 
ln -s ~/rails/your-rails-app-name/public dumbapp

access your Rails application at: “http://dumbapp.yourdomain.com”

6. You, of course, can change the symlink and subdomain names in case you all you need is a subdomained Rails app, however most of the time it is not the case, and most of the time you would want your Rails application to be accessible from a top-level domain: “http://www.yourdomain.com” (no subdomain)

All you need to do for that is to back up your “~/public_html” directory (just in case), and create a “~/public_html” symbolic link:

cd ~
mv public_html public_html_backup
rm -rf public_html/
 
# creating a symbolic link to YOUR application from "~" directory
ln -s ~/rails/your-rails-app-name/public public_html

You may want to have your “map.root” from (config/routes.rb) to be uncommented and pointed to the main controller (but that is already a pure Rails talk :) )

Now get in the blue train and hit the Rails!
Good Luck!

NOTE:
run “rails -v”
make sure you have the same Rails version in “~/rails/your-rails-app-name/config/environment.rb”.

If the version is not the same, update your ‘RAILS_GEM_VERSION’ setting in “config/environment.rb” for the Rails version Bluehost has installed, or comment out ‘RAILS_GEM_VERSION’ to use the latest version installed.

e.g.

vi ~/rails/your-rails-app-name/config/environment.rb
 
# Specifies gem version of Rails to use when vendor/rails is not present
#RAILS_GEM_VERSION = '2.1.0' unless defined? RAILS_GEM_VERSION
RAILS_GEM_VERSION = '2.2.2' unless defined? RAILS_GEM_VERSION

in case your application is built on 2.1.0, and bluehost has 2.2.2 installed (“rails -v” should give the current Rails version installed)