Deploy an Azure Web App

Tutorial: Deploying Your First Azure Web App

This comprehensive tutorial will guide you through the process of deploying a web application to Azure App Service. We'll cover the essential steps from creating your app service to deploying your code.

Prerequisites

Step 1: Create an Azure App Service

The first step is to create a new App Service instance in Azure. This will be the hosting environment for your web application.

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


az group create --name MyResourceGroup --location "East US"
az appservice plan create --name MyPlan --resource-group MyResourceGroup --sku FREE
az webapp create --name MyUniqueWebAppName --resource-group MyResourceGroup --plan MyPlan --runtime "python|3.9"
                

Replace MyUniqueWebAppName with a globally unique name for your web app.

Note: The --runtime parameter specifies the runtime stack for your application. Common values include node|18-lts, php|8.2, dotnetcore|6.0, etc.

Step 2: Prepare Your Web Application for Deployment

Ensure your application is configured correctly for a web server environment. This might involve:

  • Setting up a web.config file for .NET applications.
  • Specifying the start command for Node.js or other platforms (e.g., npm start).
  • Ensuring dependencies are listed in a requirements.txt (Python) or package.json (Node.js).

For many frameworks, Azure App Service automatically detects and configures these settings.

Step 3: Deploy Your Code

There are several ways to deploy your code to Azure App Service. We'll cover two common methods:

Method 1: Using Git Deployment

Azure App Service supports deployment directly from a Git repository.

  1. Enable Git deployment for your App Service:
    
    az webapp deployment source config-local-git --name MyUniqueWebAppName --resource-group MyResourceGroup
                            
  2. This command will output Git credentials and a remote URL. Add this remote to your local Git repository:
    
    git remote add azure <Your-Git-Remote-URL>
                            
  3. Push your code to the Azure remote:
    
    git push azure main
                            

Method 2: Using Zip Deploy

You can zip your project and deploy it using the Azure CLI.

First, create a zip file of your project's build output.


# Example for a basic project
zip -r app.zip . -x "node_modules/*" ".git/*"

az webapp deployment zip --resource-group MyResourceGroup --name MyUniqueWebAppName --src-path app.zip
                

The --src-path should point to your generated zip file.

Step 4: Verify Your Deployment

Once the deployment is complete, you can access your web application by navigating to its URL:

https://MyUniqueWebAppName.azurewebsites.net

Check your application for any errors and ensure it's functioning as expected.

Further Resources

Congratulations! You have successfully deployed your first web application to Azure App Service.

Back to Tutorials