Deploy a Web App to Azure
This tutorial guides you through the process of deploying a simple web application to Azure App Service.
Prerequisites
Before you begin, ensure you have the following:
- An Azure account. If you don't have one, sign up for a free account.
- The Azure CLI installed and configured. You can find instructions here.
- A simple web application project (e.g., HTML, CSS, JavaScript, or a framework-based app). For this tutorial, we'll assume you have a basic static website.
Step 1: Create a Resource Group
A resource group is a logical container for Azure resources. All resources deployed in this tutorial will belong to this group.
az group create --name myResourceGroup --location eastus
Replace myResourceGroup
with your desired name and eastus
with your preferred Azure region.
Step 2: Create an App Service Plan
An App Service plan defines a set of compute resources for your web app to run on.
az appservice plan create --name myAppServicePlan --resource-group myResourceGroup --sku B1 --is-linux
--name
: A unique name for your App Service plan.--resource-group
: The resource group created in Step 1.--sku B1
: Specifies the pricing tier (Basic, B1). You can choose other tiers based on your needs.--is-linux
: Specifies that you want to use a Linux-based App Service plan.
Step 3: Create a Web App
Now, create the actual web app that will host your application.
az webapp create --name mywebapp --resource-group myResourceGroup --plan myAppServicePlan --deployment-local-git
--name
: A globally unique name for your web app.--resource-group
: The resource group name.--plan
: The App Service plan created in Step 2.--deployment-local-git
: Enables local Git deployment.
NOTE: Make sure your web app name is unique across all of Azure. Azure will append a unique identifier if your chosen name is not available.
Step 4: Deploy Your Application
Navigate to your web app's directory in your local terminal and deploy using Git.
cd /path/to/your/web/app
git init
git add .
git commit -m "Initial commit"
az webapp deployment source config-local-git --name mywebapp --resource-group myResourceGroup
The last command will output a Git remote URL. Add this remote to your local repository:
git remote add azure <output_from_previous_command>
git push azure master
Step 5: Verify Deployment
Once the push is complete, your web app should be live. You can access it using the URL generated in the previous step or by navigating to:
https://mywebapp.azurewebsites.net
Replace mywebapp
with your web app's name.
Next Steps
Congratulations on deploying your first web app to Azure! Here are some suggestions for further exploration:
- Learn how to configure custom domains.
- Explore continuous deployment options from GitHub or Azure DevOps.
- Monitor your web app's performance and health.
- Implement scaling strategies for increased traffic.