This guide provides a step-by-step walkthrough for deploying a sample web application to Azure App Service.
Before you begin, ensure you have the following:
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.
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.
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:
--name MyWebAppPlan
: Your chosen name for the App Service plan.--resource-group MyWebAppResourceGroup
: The resource group created earlier.--sku B1
: Specifies the pricing tier (Basic B1 in this case). Other options include F1 (Free), S1 (Standard), etc.--is-linux
: Specifies that the plan will run on Linux-based App Service. Omit this for Windows.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.
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.
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.
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.