How-to: Host Rails App on OpenShift for FREE
There are many great options for hosting your rails application. For instances, PaaS like engine yard and heroku provide great scalability and automations to ease your deployment. VPS like Linode provides more traditional hosting services, which gives you full control of a node. But what if you just want to test your idea and have a public domain name (no tunneling and router tricks)? Then OpenShift is a great choice, cause it is FREE! (at least for your first 3 gears)
Official rails quick starter guide.
Official sample rails app on github.
Official documentation on deployment scripts.
Deployment tutorial guide.
This guide will be similar to steps described in the resouces mentioned above. I will add my thoughts to some of the steps.
1. Create an OpenShift account.
rhc gem. (If you are using
rvm, don’t use
3. Create your cartridge. This should create a folder called
4. Add database support to your application.
Here is a list of supported database.
|Short Name||Full name|
|10gen-mms-agent-0.1||10gen Mongo Monitoring Service Agent|
|mongodb-2.2||MongoDB NoSQL Database 2.2|
|mysql-5.1||MySQL Database 5.1|
|metrics-0.1||OpenShift Metrics 0.1|
|haproxy-1.4||OpenShift Web Balancer|
|postgresql-8.4||PostgreSQL Database 8.4|
|postgresql-9.2||PostgreSQL Database 9.2|
deploy script to
Add the following code to
deploy file to initialize database.
1 2 3
NOTE: This might be obvious to experienced Linux user, but I failed to realize this the first time. You have to do a
sudo chmod +x [your_rails_app_name]/.openshift/action_hooks/deploy on your
deploy script or it won’t be run by the server.
6. Change production database configuration in
config/database.yml. Then submit your change to your github repository.
1 2 3 4 5 6 7 8 9 10 11
NOTE: Remember to change adapter and ENV variable to corresponding database your are using. For example, If your are using postgresql then change
7. Download your rails application from your github repository.
1 2 3
git push will initialize the server and trigger the
deploy script. If everything goes alright, you should see your application running on
http://[your_rails_app_name]-[your_namespace].rhcloud.com. You can customize your domain name too. Check this post out to learn details.