Getting Started Deploying Ruby on Rails Apps

Page last updated:

This guide walks you through deploying a Ruby on Rails (RoR) app to Cloud Foundry. To deploy a sample RoR app, refer to the Deploy a Sample Ruby on Rails App topic.

Note: Ensure that your RoR app runs locally before continuing with this procedure.


Step 1: Create and Bind a Service Instance for a RoR Application

This section describes using the CLI to configure a PostgreSQL managed service instance for an app. For more information about creating and using service instances, refer to the Services Overview topic.

Create a Service Instance

Run cf marketplace to view managed and user-provided services and plans available to you.

Run cf create-service SERVICE PLAN SERVICE_INSTANCE to create a service instance for your app. Choose a SERVICE and PLAN from the list, and provide a unique name for the SERVICE_INSTANCE.

Bind a Service Instance

When you bind an app to a service instance, Cloud Foundry writes information about the service instance to the VCAP_SERVICES app environment variable. The app can use this information to integrate with the service instance.

Most services support bindable service instances. Refer to your service provider’s documentation to confirm whether they support this functionality.

To bind a service to an application, run cf bind-service APPLICATION SERVICE_INSTANCE.

Step 2: Configure Deployment Options

Configure the Deployment Manifest

You can specify app deployment options in a manifest that the cf push command uses. For more information about application manifests and supported attributes, refer to the Deploying with Application Manifests topic.

Configure a Production Server

Cloud Foundry uses the default standard Ruby web server library, WEBrick, for Ruby and RoR apps. However, Cloud Foundry can support a more robust production web server, such as Phusion Passenger, Puma, Thin, or Unicorn. If your app requires a more robust web server, refer to the Configuring a Production Server topic for help configuring a server other than WEBrick.

Step 3: Create the Database Configuration

For Rails versions 4.0.0 and earlier, the Ruby buildpack overwrites the config/database.yml file using the contents of the DATABASE_URL environment variable. This variable can be set by the user or will be automatically set based on bound service instances.

For Rails versions 4.1.0 and later, the Ruby buildpack will not modify the config/database.yml file.

When the app starts, the standard Rails behavior for DATABASE_URL and config/database.yml applies.

Step 4: Log in and Target the API Endpoint

Run cf login -a API_ENDPOINT, enter your login credentials, and select a space and org. The API endpoint is the URL of the Cloud Controller in your Cloud Foundry instance.

Step 5: Deploy Your App

From the root directory of your application, run cf push APP-NAME --random-route to deploy your application.

cf push APP-NAME creates a URL route to your application in the form HOST.DOMAIN, where HOST is your APP-NAME and DOMAIN is specified by your administrator. Your DOMAIN For example: cf push my-app creates the URL

The URL for your app must be unique from other apps that Cloud Foundry hosts or the push will fail. Use the following options to help create a unique URL:

  • -n to assign a different HOST name for the app.
  • --random-route to create a URL that includes the app name and random words.
  • cf help push to view other options for this command.

To view log activity while the app deploys, launch a new terminal window and run cf logs APP-NAME.

In the terminal output of the cf push command, the urls field of the App started block contains the app URL. This is the HOST_NAME you specified with the -n flag plus the domain Once your app deploys, use this URL to access the app online.

Next Steps

You’ve deployed an app to Cloud Foundry! Consult the sections below for information about what to do next.

Test a Deployed App

Use the cf CLI to review information and administer your app and your Cloud Foundry account. For example, you could edit the manifest.yml to increase the number of app instances from 1 to 3, and redeploy the app with a new app name and host name.

Manage Your Application with the cf CLI

Run cf help to view a complete list of commands, grouped by task categories, and run cf help COMMAND for detailed information about a specific command. For more information about using the cf CLI, refer to the Cloud Foundry Command Line Interface (cf CLI) topics, especially the Getting Started with the cf CLI topic.


If your application fails to start, verify that the application starts in your local environment. Refer to the Troubleshooting Application Deployment and Health topic to learn more about troubleshooting.

Create a pull request or raise an issue on the source for this page in GitHub