- Published on
- • 2 min read
Deploying Ruby On Rails Application To Cloud Application Platform - Openshift
- Authors

- Name
- Shaiju Edakulangara
- @eshaiju
OpenShift is a Platform as a Service (PaaS) from RedHat. It's great for deploying web applications as you can set up, scale, and manage apps quickly without any hassle, just like Heroku. It is open source and written in Ruby.
To get started, create a free account. You get 3 small gears (resource container/unit: one small gear is equivalent to 512 MB RAM and 1 GB storage) for free. Once you are signed up, install the OpenShift RHC Client Tools by running these commands in a terminal:
gem install rhc
rhc setup
We can deploy a Rails application by adding OpenShift as a remote repo.
Create a new application in your OpenShift account, then get the Git URL for your new application. This is shown to you when you create your application through the web console.
Add your OpenShift repo as a remote repo:
git remote add openshift <OpenShift repo URL>
- Configure the database. Since your database address may change, you will need to access it using environment variables. Add this configuration to your
database.ymlfile:
production:
adapter: mysql2
encoding: utf8
database: <%= ENV['OPENSHIFT_APP_NAME'] %>
pool: 5
host: <%= ENV['OPENSHIFT_MYSQL_DB_HOST'] %>
port: <%= ENV['OPENSHIFT_MYSQL_DB_PORT'] %>
username: <%= ENV['OPENSHIFT_MYSQL_DB_USERNAME'] %>
password: <%= ENV['OPENSHIFT_MYSQL_DB_PASSWORD'] %>
socket: <%= ENV['OPENSHIFT_MYSQL_DB_SOCKET'] %>
- Deploy to OpenShift:
git push openshift master
If everything went well, your app should deploy and be accessible. If not, pay attention to the output from the git push.
If your application requires persistent storage, you can use the directory app-root/data/. You can access this directory in your application using the environment variable OPENSHIFT_DATA_DIR.
- Managing apps:
# SSH into your server
rhc ssh app-name
# Navigate to app folder
cd app-root/repo
# Migrate Database
bundle exec rake db:migrate RAILS_ENV="production"
# Add custom domain
rhc alias add railsapp www.yourdomain.com
Then change CNAME records in your DNS provider account.