Deploy a Web App to Azure
This tutorial guides you through the process of deploying a simple web application to Azure App Service. Azure App Service is a fully managed platform that enables you to build and host web apps, mobile back ends, and RESTful APIs in the programming language of your choice without managing infrastructure.
Step 1: Prerequisites
Before you begin, ensure you have the following:
- An Azure account with an active subscription. If you don't have one, you can create a free account.
- The Azure CLI installed on your local machine. You can download it from here.
- A basic understanding of Git.
This tutorial assumes you have a sample web application ready, for example, a Node.js Express app, a Python Flask app, or a .NET Core app. For this example, we'll use a placeholder for your app's code.
Step 2: 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 your Azure account.
Step 3: Create an Azure Resource Group
A resource group is a logical container that holds related Azure resources. Create a new resource group for your web app:
az group create --name MyWebAppResourceGroup --location eastus
Replace MyWebAppResourceGroup
with your desired resource group name and eastus
with your preferred Azure region.
Step 4: Create an App Service Plan
An App Service plan defines a set of compute resources for your web app. Create a new App Service plan:
az appservice plan create --name MyWebAppPlan --resource-group MyWebAppResourceGroup --sku B1 --is-linux
--name
: A unique name for your App Service plan.--resource-group
: The name of the resource group created in the previous step.--sku B1
: Specifies the pricing tier. B1 is a cost-effective choice for testing. You can explore other SKUs like F1 (free) or S1 (standard).--is-linux
: Specifies that the plan will run on Linux. For Windows, omit this flag or use--is-windows
.
Step 5: Create Your Web App
Now, create your web app within the App Service plan. This command assumes you'll be deploying your code using Git.
az webapp create --name MyAwesomeWebApp123 --resource-group MyWebAppResourceGroup --plan MyWebAppPlan --deployment-source-url https://github.com/Azure-Samples/nodejs-docs-hello-world.git --deployment-source-branch main
--name
: A globally unique name for your web app. Azure will append a default domain name.--resource-group
: Your resource group name.--plan
: Your App Service plan name.--deployment-source-url
: The URL of your Git repository containing your web app code.--deployment-source-branch
: The branch to deploy from.
For this example, we're using a sample Node.js repository. Replace this with your actual repository URL and branch.
Step 6: Browse Your Web App
Once the deployment is complete, you can browse your web app. You can find its URL in the output of the previous command, or by running:
az webapp show --name MyAwesomeWebApp123 --resource-group MyWebAppResourceGroup --query "defaultHostName"
Open this URL in your web browser to see your deployed web application.
Next Steps
Congratulations! You have successfully deployed a web app to Azure App Service. Consider exploring these next steps:
- Set up continuous deployment from GitHub or Azure DevOps.
- Configure a custom domain for your web app.
- Add an SSL certificate to secure your app.
- Scale your web app to handle more traffic.