Deploy a rails application on Bluehost
December 4, 2008 – 12:03 amDeploying a rails application on Bluehost for the first time is not a fun task, especially if you are fairly new to rails development. I hope the following details may save someone some of the hair-loss inducing troubles I experienced. Having said that I’m happy with Bluehost thus far. I have a Word Press blog, rails application, and PHP application all running via Bluehost.
mkdir ~/rails
cd ~/rails
rails app_name
cd app_name
From within cPanel, select Sub-Domains and create a new sub-domain with the same name as the rails application folder you just created.
cd ~/public_html/
rm -r app_name
ln -s /home/YOUR_USERNAME/rails/first/public app_name
ln -s ~/rails/app_name/public app_name
go the website -> it works!
Now db…
How to create a rails migration for an existing database
I had done things a little backwards with my first rails application so I wanted to create a rails migration file from my existing database (rather than the other way around). I did this as follows:
$ rake -T db:schema:dump for documentation
$ rake -T db:schema:dump
This creates a db\schema.rb file for you. Remove all existing migration files (if any) from your db\migrate folder. Create a new migration file and then copy the contents from db\schema.rb into this new migration file. Done!
Create database user, databases, and then assign user to the databases
- create user, create db’s, assign users to db via cPanel
- edit database.yml. Here’s what I used for the development database…
development:
adapter: mysql
database: db_name
host: localhost
username: username
password: password - upload migration file
- $ rake db:migrate [PATH_ENV=development|test|production]
Note: environment is development by default.
../public/
$ ruby dispatch.rb
$ rails -v
environment.rb
I added the following to my environment.rb file. Note that the base of the path was home1 not home as specified in one of the Bluehost knowledge base articles. Use the linux shell command ‘pwd’ to determine what your path is. Set ENV['RAILS_ENV'] to development, test, or production as desired.
ENV['RAILS_ENV'] = ‘development’
ENV["GEM_PATH"]= “/home1/YOUR_HOME/ruby/gems:/usr/lib/ruby/gems/1.8″
Internal Server Error or Application failed to start errors
If you’re getting errors like above you may assume incorrectly as I did that this is a production server friendly error message and your real error message is being hidden. (Especially if you’re from a ASP.NET background where this is common practise). You’ll be searching through the cPanel error log and your rails app log files and not find anything useful. This is because you have something configured incorrectly and your rails app is not actually starting at all. Although rails applications on Bluehost are not using the Webrick server, you may be able to determine why your application is not starting by trying to start the webrick server. I found this sometimes produced useful information:
$ cd ~/rails/app_name
$ script/server
…
useful error message
…
rake db:migrate
Once I had everything working, I needed to perform some db:migrate tasks from the command line. When I tried to do this however it failed saying “Missing these required gems: mislav-will_paginate”. It suggested I run “rake gems:install”. I was using this successfully in my site however I decided to run “rake gems:install” anyway. This also failed however, saying “Permission denied” to my gems path. I then tried the following:
$ export GEM_PATH=~/ruby/gems
Then tried my db:migrate command again:
$ rake db:migrate VERSION=0
Success! It just wasn’t finding the mislav-will_paginate gem even though it was installed.
2 Responses to “Deploy a rails application on Bluehost”
Hi
I have hosted most of my sites on Bluehost due to it’s amazing features.I am working on Rails and still in the begining stage.I have created few simple and primitive rails application.I found your above writeup on hosting rails on bluehost lucratively simple but I am missing some points somehow.
Can you tell me when u will be online so that i can ask you few doubts and help myself to install rails app in my server.
Thanks
My email id is
pkaarthikeyan@gmail.com
Please add me to your gmail address book
By pinastro on Jun 14, 2009
Feel free to post questions here if you like.
By admin on Jun 22, 2009