Deploying rails application on to OPENSHIFT + via RHC client tool

Want to deploy your Ruby on Rails application on openshift? then follow these steps,

1) Go to and create an account

2) Click MY APPS > Create an application and select Ruby on rails as the type of the application.

3) Put a name for your application. If this is your first time… make sure that you have a unique namespace. You can change it here:

4) Clone your git repo into your local machine via the ssh codes provided…


git clone ssh://
cd railsapp/

5) or I recommend to use rhc client tool to create app on openshift

sudo gem install rhc (first install gem rhc)
rhc app create -a railsapp -t ruby-1.9

6) Then to add cartridge to your rails application use

rhc cartridge add -a railsapp -c mysql-5.1

7) Then pull your code from github,

git remote add upstream -m master git://
git pull -s recursive -X theirs upstream master

8) Then you will need to change, your database.yml put this config for production only…

  adapter: mysql2
  encoding: utf8
  database: <%=ENV['OPENSHIFT_APP_NAME']%>
  pool: 5

Leave the development and test ENV under mysql adapter.

9) Now in your application directory look for .openshift folder

there you will find .openshift/action_hooks/deploy file
pushd ${OPENSHIFT_REPO_DIR} > /dev/null
  bundle exec rake db:migrate RAILS_ENV="production"
popd > /dev/null

commands written between pushd and popd lines will get executed automatically after code is updated on openshift,so if you have any other commands like starting resque, or copying some files after deploy then you can add it here.

10) Now that we have made our changes… push it!

git add
git commit -m “configures database.yml,gemfile and adds .openshift files”
git push

11) That’s all, now check url for your rails app.

12) here you will find all enviroment variables details that are available in openshift.

13) If you want to associate your own domain name eg. ( with your openshift rails app url then you will need to create url alias as shown below

rhc alias add railsapp

then change cname records in your DNS provider account. _config.yml

14) If your application require some persistent directory for your data then you can use directory (app-root/data/) you can access this directory in your application using enviroment variable OPENSHIFT_DATA_DIR

15) If you want to remove a cartridge

$rhc cartridge remove shortname –app appname –confirm

$rhc cartridge remove mysql2  –app railsapp –confirm
Written on April 24, 2013