INTRODUCTION
Azure CLI and ARM (Azure Resource Manager) templates help make the process of deploying a web application on Azure more efficient. By defining your infrastructure as code using ARM templates, deployments become consistent and repeatable. This is a detailed tutorial on how to use an ARM template and the Azure CLI to launch a PHP web application.
PROCEDURE
Step 1: Create the ARM Template
1.Create a new folder e.g. web-app using this code.
cd web-app
2.The ARM template (template.json
) defines the resources needed for your web app, such as the App Service Plan and the Web App itself. Here’s the template:
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"resources": [
{
"type": "Microsoft.Web/serverfarms",
"apiVersion": "2021-01-15",
"name": "[parameters('appServicePlanName')]",
"location": "[resourceGroup().location]",
"sku": {
"name": "F1",
"tier": "Free",
"size": "F1",
"family": "F",
"capacity": 1
}
},
{
"type": "Microsoft.Web/sites",
"apiVersion": "2021-01-15",
"name": "[parameters('webAppName')]",
"location": "[resourceGroup().location]",
"properties": {
"serverFarmId": "[resourceId('Microsoft.Web/serverfarms', parameters('appServicePlanName'))]",
"siteConfig": {
"appSettings": [
{
"name": "SCM_DO_BUILD_DURING_DEPLOYMENT",
"value": "true"
}
]
}
}
}
],
"parameters": {
"appServicePlanName": {
"type": "string"
},
"webAppName": {
"type": "string"
}
}
}
Step 2: Define Parameters
The parameters.json
file provides values for the parameters defined in the ARM template:
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"appServicePlanName": {
"value": "myAppServicePlan"
},
"webAppName": {
"value": "akinWebApp987"
}
}
}
Step 3: Create a Resource Group
Before deploying, create a resource group to hold your resources:
az group create --name web-rg --location eastus
Step 4: Create the App Service Plan (if it doesn’t exist)
If the App Service Plan does not exist, you can create it manually using the Azure CLI:
az appservice plan create --name myAppServicePlan --resource-group web-rg --sku F1 --location eastus
This creates a new App Service Plan named myAppServicePlan with the Free tier (F1).
Step 5: Deploy the ARM Template
Use the Azure CLI to deploy the ARM template and parameters file:
az deployment group create --resource-group web-rg --template-file template.json --parameters parameters.json
Step 6: Deploy Code from GitHub
To deploy your PHP application code from a GitHub repository, use the following command:
az webapp deployment source config --name akinWebApp987 --resource-group web-rg --repo-url https://github.com/yourtechie/fruitables --branch master --manual-integration
This command connects your web app to the GitHub repository and deploys the code.
CONCLUSION
Create an ARM template, deploy Azure CLI, and connect the web app to GitHub for continuous deployment, ensuring a consistent, automated process for managing and scaling the web app on Azure.
Top comments (0)