MSDN Tutorials

Learn to build and deploy with confidence.

Deploying Your Application to Azure App Service

Azure App Service is a fully managed platform for building, deploying, and scaling web apps and APIs. This tutorial will guide you through the process of deploying a sample application to Azure App Service using common deployment methods.

Prerequisites

Step 1: Create an Azure App Service

You can create an App Service instance through the Azure portal, Azure CLI, or other tools. We'll use the Azure CLI for this example.

Using Azure CLI

Open your terminal or Azure Cloud Shell and run the following commands:


# Log in to your Azure account
az login

# Set your subscription (replace with your actual subscription ID)
az account set --subscription "YOUR_SUBSCRIPTION_ID"

# Create a resource group (if you don't have one already)
az group create --name MyResourceGroup --location "East US"

# Create an App Service Plan (defines the underlying compute resources)
# Using F1 (Free) tier for demonstration. For production, choose a suitable tier.
az appservice plan create --name MyAppServicePlan --resource-group MyResourceGroup --sku F1 --is-linux

# Create the Web App
az webapp create --name MyUniqueWebAppName --resource-group MyResourceGroup --plan MyAppServicePlan --runtime "DOTNETCORE:6.0"
# Note: Replace "DOTNETCORE:6.0" with your desired runtime, e.g., "NODE:18-lts", "PYTHON:3.9", "PHP:8.1"
            

Remember to replace MyUniqueWebAppName with a globally unique name for your web app. If the name is taken, you'll need to choose another one.

Step 2: Choose a Deployment Method

Azure App Service supports various deployment methods, including:

For this tutorial, we'll focus on Local Git and GitHub integration.

Step 3: Deploying via Local Git

This method is straightforward for quick deployments.

Configure Deployment Credentials

You need to set deployment credentials for your App Service. You can use user-level credentials or scm-user credentials. User-level credentials apply to all apps in your subscription.


# Set user-level deployment credentials (choose a username and password)
az webapp deployment user set --user-name  --password 
            

Important: Save these credentials securely. They are used for all Git-based deployments to your App Service.

Configure Local Git Repository

Navigate to your application's root directory in your local terminal.


# Initialize a Git repository if you haven't already
git init

# Add your application files
git add .
git commit -m "Initial commit"

# Add Azure App Service as a remote repository
# Replace MyUniqueWebAppName with your actual web app name
git remote add azure https://<your_username>:<your_password>@myuniquewebappname.scm.azurewebsites.net:443/MyUniqueWebAppName.git
            

You'll be prompted for the username and password you set in the previous step.

Push to Azure

Now, push your code to the Azure remote. This deploys your application.


git push azure master
            

If your default branch is not master, use its name instead (e.g., main).

Note: For some runtimes, you might need to configure build processes. Azure App Service often handles common build tasks automatically, but for complex scenarios, consider using Azure DevOps or GitHub Actions for more control.

Step 4: Deploying via GitHub Integration (Continuous Deployment)

This method sets up a pipeline where changes pushed to your GitHub repository automatically trigger a deployment to Azure App Service.

Connect GitHub to Azure App Service

  1. Navigate to your Web App in the Azure portal.
  2. In the left-hand menu, under Deployment, select Deployment Center.
  3. Choose GitHub as your source.
  4. Authorize Azure to access your GitHub account.
  5. Select your repository and the branch you want to deploy from.
  6. Configure any build settings if prompted (Azure often detects common project types).
  7. Click Save.

Azure will set up a GitHub Actions workflow (or a similar CI/CD pipeline) that monitors your chosen branch. Pushing new commits to that branch will automatically redeploy your application.

Step 5: Verifying Your Deployment

Once the deployment is complete, you can access your web application by navigating to its URL. This will be in the format: https://MyUniqueWebAppName.azurewebsites.net.

You can also monitor deployment logs and application health from the Deployment Center and App Service logs sections in the Azure portal.

Troubleshooting Tips:

Conclusion

You have successfully deployed an application to Azure App Service! Azure App Service offers numerous features for managing your applications, including custom domains, SSL certificates, autoscaling, and integrated monitoring. Explore the Azure portal to discover these capabilities.