|

How to Create Azure App Service Plan and Web App Using Azure CLI

How to Create an Azure App Service Plan and Web App with the Azure CLI

Azure gives you many ways to deploy resources. The portal works. ARM templates work. But the Azure CLI is fast and repeatable. Here is how to spin up a web app and app service plan using only commands.

Why Use the CLI?

The GUI is fine for one-off tasks. But scripts are better when you need consistency. You can save these commands. Run them again. Share them with your team. No clicking required.

Create Your Resource Group First

Everything in Azure lives in a resource group. Start there.

bashaz group create \
  --name rg-cliwebapp \
  --location uksouth

This gives you a container for your app and its plan.

Create the App Service Plan

You cannot create a web app without a plan. The plan defines your compute resources. Here is how to make a free one.

bashaz appservice plan create \
  --name free-appservice-plan \
  --resource-group rg-cliwebapp \
  --sku FREE

Note: The SKU value is FREE. Other options include B1, S1, P1v2, and more. Pick based on your needs.

Create the Web App

Now you can create the actual web app.

bashaz webapp create \
  --name my-cli-webapp \
  --resource-group rg-cliwebapp \
  --plan free-appservice-plan

Important: Your web app name must be unique across all of Azure. It becomes part of your URL (yourname.azurewebsites.net). If someone else took the name, you will get an error. Try again with a different name.

Deploy Code from GitHub

You have a shell of a web app. Now put code in it. You can deploy from Visual Studio or VS Code. But here is how to pull directly from a GitHub repo.

bashaz webapp deployment source config \
  --name my-cli-webapp \
  --resource-group rg-cliwebapp \
  --repo-url https://github.com/yourusername/yourrepo \
  --branch main \
  --manual-integration

The --manual-integration flag means Azure will not auto-deploy when you push new code. You control when to sync.

This step takes a few minutes. Azure pulls your code, builds it if needed, and deploys it.

Verify Everything Works

Open your browser. Go to:

texthttps://my-cli-webapp.azurewebsites.net

You should see your deployed application. Check the Deployment Center in the Azure portal if you need to verify the GitHub connection.

Summary

You now have a repeatable way to deploy Azure web apps. Save these commands. Modify the names and SKUs. Run them whenever you need a new environment. The CLI turns a multi-click portal process into a script you can run in seconds.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *