Deploy a Web App using Git
This tutorial guides you through the process of deploying a web application to Azure App Service using Git. Azure App Service provides a fully managed platform for building, deploying, and scaling web apps and APIs.
Prerequisites
- An Azure account. If you don't have one, Sign up for a free trial.
- A Git repository containing your web application code.
- Azure CLI installed locally (optional, but recommended).
Step 1: Create an Azure App Service
First, you need to create an App Service instance in Azure. You can do this via the Azure portal or using the Azure CLI.
Option 1: Using the Azure Portal
- Go to the Azure portal.
- Click Create a resource.
- Search for "Web App" and select it.
- Click Create.
- Fill in the required details:
- Subscription: Select your Azure subscription.
- Resource Group: Create a new one or select an existing one.
- Name: A unique name for your web app (e.g.,
my-git-web-app-xyz
). This will be part of the URL. - Runtime stack: Choose your application's runtime (e.g., Node.js, Python, .NET).
- Operating System: Select your desired OS.
- Region: Choose the Azure region closest to your users.
- App Service Plan: Create a new one or select an existing one. Choose a pricing tier appropriate for your needs.
- Click Review + create, then Create.
Option 2: Using Azure CLI
Open your terminal or command prompt and run the following commands:
# Log in to your Azure account
az login
# Set your subscription (if you have multiple)
az account set --subscription ""
# Create a resource group (if you don't have one)
az group create --name myResourceGroup --location "East US"
# Create the App Service
az webapp create --resource-group myResourceGroup --name my-git-web-app-xyz --plan my-app-service-plan --runtime "NODE:18-lts"
Replace myResourceGroup
, my-git-web-app-xyz
, my-app-service-plan
, and the runtime as needed.
Step 2: Configure Deployment Source
Once your App Service is created, you need to configure it to deploy from your Git repository.
Option 1: Using the Azure Portal
- Navigate to your newly created App Service in the Azure portal.
- In the left-hand menu, under Deployment, click Deployment Center.
- Under the Source control tab, select GitHub, Bitbucket, Local Git, or Azure Repos based on where your code is hosted.
- Follow the prompts to authorize Azure to access your repository and select the branch you want to deploy from. If you choose Local Git, Azure will provide you with a Git URL and credentials to push directly to your App Service.
Option 2: Using Azure CLI (for Local Git deployment)
To set up local Git deployment:
# Get deployment credentials for your App Service
az webapp deployment list-publishing-credentials --name my-git-web-app-xyz --resource-group myResourceGroup --json-file
# From the output, find the "scmUrl" for your chosen runtime (e.g., Git URL for Node.js is often: https://username@appname.scm.azurewebsites.net/myapp.git)
# Add this remote to your local Git repository
git remote add azure <your-azure-git-url>
# Push your code to Azure
git push azure main
You will be prompted for the deployment username and password provided by the list-publishing-credentials
command.
Step 3: Deploy Your Code
With the deployment source configured, you can now deploy your application.
- If using GitHub, Bitbucket, or Azure Repos: Azure will automatically build and deploy your application whenever you push changes to the configured branch. You can monitor the deployment progress in the Deployment Center.
- If using Local Git: Simply push your latest code changes to the
azure
remote you added:git push azure main
Step 4: Verify Your Deployment
After the deployment is complete, navigate to your web app's URL (e.g., https://my-git-web-app-xyz.azurewebsites.net
) to see your application live on Azure!
Troubleshooting
If you encounter issues:
- Check the deployment logs in the Azure portal's Deployment Center.
- Ensure your application's dependencies are correctly managed (e.g.,
package.json
for Node.js,requirements.txt
for Python). - Verify that your application is configured to listen on the port specified by the
PORT
environment variable in Azure App Service.
Congratulations! You have successfully deployed your web application to Azure App Service using Git.
Explore More Tutorials