Create a Ruby App in App Service on Linux

App Service on Linux provides a highly scalable, self-patching web hosting service. This quickstart shows you how to create a basic Ruby on Rails application you then deploy it to Azure as a Web App on Linux.


If you don't have an Azure subscription, create a free account before you begin.


Download the sample

In a terminal window, run the following command to clone the sample app repository to your local machine:

git clone

Run the application locally

Run the rails server in order for the application to work. Change to the hello-world directory, and the rails server command starts the server.

cd hello-world\bin
rails server

Using your web browser, navigate to http://localhost:3000 to test the app locally.


Modify app to display welcome message

Modify the application so it displays a welcome message. First, you must setup a route by modifying the ~/workspace/ruby-docs-hello-world/config/routes.rb file to include a route named hello.

Rails.application.routes.draw do
    #For details on the DSL available within this file, see
    root 'application#hello'

Change the application's controller so it returns the message as HTML to the browser.

Open ~/workspace/hello-world/app/controllers/application_controller.rb for editing. Modify the ApplicationController class to look like the following code sample:

class ApplicationController > ActionController :: base
  protect_from_forgery with: :exception
  def hello
    render html: "Hello, world from Azure Web App on Linux!"

Your app is now configured. Using your web browser, navigate to http://localhost:3000 to confirm the root landing page.

Hello World configured

Launch Azure Cloud Shell

The Azure Cloud Shell is a free interactive shell that you can use to run the steps in this article. It has common Azure tools preinstalled and configured to use with your account. Just click the Copy to copy the code, paste it into the Cloud Shell, and then press enter to run it. There are a few ways to launch the Cloud Shell:

Click Try It in the upper right corner of a code block. Cloud Shell in this article
Open Cloud Shell in your browser.
Click the Cloud Shell button on the menu in the upper right of the Azure portal. Cloud Shell in the portal

Create a deployment user

In the Cloud Shell, create deployment credentials with the az webapp deployment user set command. This deployment user is required for FTP and local Git deployment to a web app. The user name and password are account level. They are different from your Azure subscription credentials.

In the following example, replace <username> and <password> (including brackets) with a new user name and password. The user name must be unique within Azure. The password must be at least eight characters long, with two of the following three elements: letters, numbers, symbols.

az webapp deployment user set --user-name <username> --password <password>

You should get a JSON output, with the password shown as null. If you get a 'Conflict'. Details: 409 error, change the username. If you get a 'Bad Request'. Details: 400 error, use a stronger password.

You create this deployment user only once; you can use it for all your Azure deployments.


Record the user name and password. You need them to deploy the web app later.

Create a Ruby web app on Azure

A resource group is required to contain the assets needed for your web app. To create a resource group, use the az group create command.

az group create --location westeurope --name myResourceGroup

Use the az appservice plan create command to create an app service plan for your web app.

az appservice plan create --name myAppServicePlan --resource-group myResourceGroup --is-linux

Next, issue the az webapp create command to create the web app that uses the newly created service plan. Notice that the runtime is set to ruby|2.3. Don't forget to replace <app name> with a unique app name.

az webapp create --resource-group myResourceGroup --plan myAppServicePlan --name <app name> \
--runtime "ruby|2.3" --deployment-local-git

The output from the command reveals information about the newly created web app as well as the deployment URL. It should look similar to the following sample. Copy the URL for later use in this tutorial.

https://<deployment user name>@<app name><app name>.git

Once the web app is created, an Overview page is available to view. Navigate to it. The following splash page is displayed:

Splash page

Deploy your application

Run the following commands to deploy the local application to your Azure website:

git remote add azure <Git deployment URL from above>
git add -A
git commit -m "Initial deployment commit"
git push azure master

Confirm that the remote deployment operations report success. The commands produce output similar to the following text:

remote: Using sass-rails 5.0.6
remote: Updating files in vendor/cache
remote: Bundle gems are installed into ./vendor/bundle
remote: Updating files in vendor/cache
remote: ~site/repository
remote: Finished successfully.
remote: Running post deployment command(s)...
remote: Deployment successful.
To https://<your web app name><your web app name>.git
  579ccb....2ca5f31  master -> master
myuser@ubuntu1234:~workspace/<app name>$

Once the deployment has completed, restart your web app for the deployment to take effect by using the az webapp restart command, as shown here:

az webapp restart --name <app name> --resource-group myResourceGroup

Navigate to your site and verify the results.

http://<app name>

updated web app


While the app is restarting, attempting to browse the site results in an HTTP status code Error 503 Server unavailable. It may take a few minutes to fully restart.

Clean up deployment

After the sample script has been run, the following command can be used to remove the resource group and all resources associated with it.

az group delete --name myResourceGroup

Next steps