Deploying Your Web App to Azure

This guide provides a step-by-step walkthrough for deploying a sample web application to Azure App Service.

Prerequisites

Before you begin, ensure you have the following:

Log in to Azure

Open your terminal or command prompt and log in to your Azure account using the Azure CLI:

az login

This command will open a browser window for you to authenticate. After successful login, you should see your subscription information.

Create an Azure Resource Group

A resource group is a logical container that holds related resources for an Azure solution. Create one using the following command:

az group create --name MyWebAppResourceGroup --location eastus

Replace MyWebAppResourceGroup with your desired name and eastus with your preferred Azure region.

Command executed. Resource group 'MyWebAppResourceGroup' created in location 'eastus'.
Create an App Service Plan

An App Service plan defines a set of computing resources for your web app. This plan determines the performance, features, and cost.

az appservice plan create --name MyWebAppPlan --resource-group MyWebAppResourceGroup --sku B1 --is-linux

Here:

Create the Web App

Now, create the actual web app instance. This is where your code will be deployed.

az webapp create --name MySampleAzureWebApp --resource-group MyWebAppResourceGroup --plan MyWebAppPlan

--name MySampleAzureWebApp: This name must be globally unique across Azure.

Created web app MySampleAzureWebApp in resource group MyWebAppResourceGroup.
Default Hostname: my-sample-azure-web-app.azurewebsites.net
Deploy Your Code

Azure App Service supports various deployment methods. One common method is using Git deployment.

Option A: Deploying from a Local Git Repository

If your web app is a Git repository, you can deploy directly:

az webapp deploy --resource-group MyWebAppResourceGroup --name MySampleAzureWebApp --src-path /path/to/your/web-app-source --type zip

Replace /path/to/your/web-app-source with the path to your application's root folder. Using --type zip deploys your code as a zip file, which is generally more reliable.

Option B: Deploying from GitHub/Azure DevOps

You can also configure Continuous Integration/Continuous Deployment (CI/CD) from your Git repository.

Navigate to your web app in the Azure portal. Under "Deployment Center," you can connect to GitHub, Azure Repos, or other sources to set up automated deployments.

Deployment successful.
Your web app is now live at: http://MySampleAzureWebApp.azurewebsites.net
Test Your Web App

Open your web browser and navigate to the default hostname you received in Step 5 (e.g., http://MySampleAzureWebApp.azurewebsites.net). You should see your deployed web application.

If you encounter issues, check the "Log stream" or "Deployment logs" within your App Service configuration in the Azure portal for troubleshooting.

Clean Up (Optional)

To avoid ongoing charges, you can delete the resource group and all its contained resources when you are finished:

az group delete --name MyWebAppResourceGroup --yes --no-wait

This command will remove the resource group, App Service plan, and the web app itself.