Monthly Archives: July 2014

Running a Rails application on Openshift server tutorial

Before we start this short tutorial you must make sure you have ruby and then ruby on rails installed on your local machine.  Type in ruby -v  to see which version you have, then type rails -v to see the version of rails you have.  If not you must install them, installing ruby and then rails can be a pain so make sure to read the documentation and when you run into problems just copy and paste the errors so you can google it.  Someone else has already solved your issue and posted it online.


Some of these commands won’t work so type sudo before those commands.

If you just added gems to your gem files make sure you type bundle install after(making sure you are in the correct app directory).  Then restart the rails server to use those changes.

To start rails server type: rails server

Or for short type: rails s

MongoDB must be running in the background so make sure you download mongodb and open up a terminal then type: sudo mongod

then press command tab to open up a new terminal tab, since we don’t want to close out the mongod server by accident.  To shut down the server press control C to properly kill the server.



Now to create a rails applications on our openshift account.

Go to your Openshift account and login.  You will create your application by selecting Rails cartridge, the Github repo is already filled in so leave it there and give the app a name.  Click create application.

We will be running our Rails app with a MongoDB as our database.  To do this just add MongoDB cartridge once openshift is done creating your app.

We don’t need the files that were automatically created for us when creating this app so you can go to your app folder and manually just highlight all the files and delete them, or simply on the terminal (make sure your inside your new app directory) type

sudo rm -rf *

The sudo part just gives you authorization to do more administrative changes to the files on your computer (Be very careful where you use that command it will delete files you might not have intended to delete, make sure your in the correct directory!!!).

Now that all the files were removed we need to add our files by either cloning the repo that we will work on from

or just run on terminal:  git remote add upstream -m master 

git pull -s recursive -X theirs upstream master

That will give you the code for this sample project to get us more familiar with using rails as our framework.  Go ahead and save your changes with git add -A, and git commit -m “”, then push to your repository.

In this case:  git push upstream master


If you want you can also create your rails app just on the terminal, by typing:

rhc app create ruby-1.9 -a yourappname

(this will already clone the app to our local machine, you can check your folder for the new files)

Then add our MongoDB database by typing:

rhc cartridge add mongodb-2.4 -a yourappname

Now make sure to work out of our new app directory so cd into your new app directory.



Next step is to login using ssh to our openshift server.  We do this by going to our app on openshift, clicking on the right side you will see this message

Remote Access

click on it and copy the ssh secret code shown.  Now paste that on your terminal and press enter, this will let you run a Secure shell session ssh on your openshift server.

Now on terminal type ls to see a list of your files.  Then we need to run the command rake secret in the app-root/runtime/repo  folder so to get there just cd into app-root, then cd into runtime and cd into repo then type rake secret, it should look like this.

cd app-root

cd runtime

cd repo

Or do it all at once: cd app-root/runtime/repo

rake secret

Once that’s done it will give you a long secret key copy that.  (command C)


Then type:  rhc setup

That will give you a list of app names, look for the one you just made.

Now type:

rhc set-env SECRET_KEY_BASE=yourSecretCodeFromTheServerWeJustGot -a yourOpenShiftAppName

Now we must restart our app by typing:

rhc app-stop yourOpenShiftAppName rhc app-start yourOpenShiftAppName


Finally after this if you go to your open shift account and click on your app it should work!  Good job if you’ve made it this far!

-keep moving




Tagged , , ,