0
0
Azurecloud~5 mins

Creating a web app in Azure - Step-by-Step CLI Walkthrough

Choose your learning style9 modes available
Introduction
Creating a web app lets you run your website or web service on the cloud. This means your app is always available and can handle many users without needing your own server.
When you want to quickly launch a website without buying or managing servers.
When you need your app to be accessible from anywhere in the world.
When you want automatic scaling to handle more visitors during busy times.
When you want to focus on writing code and not on server maintenance.
When you want to deploy updates easily without downtime.
Commands
This command logs you into your Azure account so you can manage resources.
Terminal
az login
Expected OutputExpected
To sign in, use a web browser to open the page https://microsoft.com/devicelogin and enter the code ABCD1234 to authenticate. You have logged in. Now let us find all the subscriptions to which you have access...
Creates a resource group named 'myResourceGroup' in the East US region to hold your web app and related resources.
Terminal
az group create --name myResourceGroup --location eastus
Expected OutputExpected
{ "id": "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/myResourceGroup", "location": "eastus", "managedBy": null, "name": "myResourceGroup", "properties": { "provisioningState": "Succeeded" }, "tags": {}, "type": "Microsoft.Resources/resourceGroups" }
--name - Specifies the name of the resource group
--location - Specifies the Azure region for the resources
Creates an App Service plan named 'myAppServicePlan' in the resource group. This plan defines the pricing tier and OS for your web app.
Terminal
az appservice plan create --name myAppServicePlan --resource-group myResourceGroup --sku B1 --is-linux
Expected OutputExpected
{ "id": "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/myResourceGroup/providers/Microsoft.Web/serverfarms/myAppServicePlan", "location": "eastus", "name": "myAppServicePlan", "properties": { "status": "Ready", "workerTierName": null }, "sku": { "capacity": 1, "family": "B", "name": "B1", "size": "B1", "tier": "Basic" }, "type": "Microsoft.Web/serverfarms" }
--sku - Sets the pricing tier (B1 is Basic small)
--is-linux - Specifies the plan is for Linux-based apps
Creates the web app named 'myUniqueWebApp123' in the resource group using the App Service plan. It sets the runtime environment to Node.js 14 LTS.
Terminal
az webapp create --resource-group myResourceGroup --plan myAppServicePlan --name myUniqueWebApp123 --runtime "NODE|14-lts"
Expected OutputExpected
{ "id": "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/myResourceGroup/providers/Microsoft.Web/sites/myUniqueWebApp123", "location": "eastus", "name": "myUniqueWebApp123", "properties": { "enabled": true, "hostNames": [ "myUniqueWebApp123.azurewebsites.net" ], "state": "Running" }, "type": "Microsoft.Web/sites" }
--runtime - Specifies the language and version for the app
Shows details about the web app to confirm it was created and is running.
Terminal
az webapp show --resource-group myResourceGroup --name myUniqueWebApp123
Expected OutputExpected
{ "id": "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/myResourceGroup/providers/Microsoft.Web/sites/myUniqueWebApp123", "location": "eastus", "name": "myUniqueWebApp123", "properties": { "state": "Running", "hostNames": [ "myUniqueWebApp123.azurewebsites.net" ] }, "type": "Microsoft.Web/sites" }
Key Concept

If you remember nothing else from this pattern, remember: create a resource group first, then an App Service plan, and finally the web app itself.

Common Mistakes
Trying to create a web app without first creating a resource group.
Azure needs a resource group to organize and manage resources; without it, the web app creation fails.
Always create or specify an existing resource group before creating the web app.
Using a web app name that is not globally unique.
Web app names must be unique across Azure because they form part of the URL; duplicates cause errors.
Choose a unique name, often by adding random numbers or your initials.
Not specifying the runtime environment when creating the web app.
Without the runtime, Azure cannot set up the correct environment for your app code, causing deployment issues.
Always specify the runtime with the --runtime flag matching your app's language and version.
Summary
Log in to Azure and create a resource group to hold your app resources.
Create an App Service plan to define the pricing and environment for your web app.
Create the web app with a unique name and specify the runtime environment.
Verify the web app is running and accessible.