Home Microsoft AzureDeploy a Scalable WordPress Site on Azure App Service

Deploy a Scalable WordPress Site on Azure App Service

by Knowledge Base Linux
Deploy a Scalable WordPress Site on — Deploy a Scalable WordPress Site on Azure App Service

Running WordPress on a single virtual machine works until it doesn’t: traffic spikes exhaust RAM, a failed disk takes the site down, and scaling means a painful migration. Azure App Service solves this with a fully managed platform for web apps — built-in load balancing, autoscaling, deployment slots, and TLS — so your WordPress site stays fast and available without you managing the underlying servers. Combined with Azure Database for MySQL Flexible Server, you get a production-grade WordPress stack that scales horizontally in minutes.

In this guide, you will deploy a scalable WordPress site on Azure App Service using the Azure CLI: create the resource group and App Service plan, provision a managed MySQL database, deploy WordPress, configure Redis object caching, enable autoscale rules, set up automated backups, and harden the installation. Every step uses repeatable commands you can save as a deployment script.

Prerequisites for Azure App Service WordPress – Deploy a Scalable WordPress Site on

You will need:

  • An Azure subscription with Owner or Contributor access to a resource group.
  • The Azure CLI installed and logged in (az login), version 2.50 or newer.
  • A custom domain with access to its DNS zone (optional but recommended for production).
  • Familiarity with managed databases — the Azure Database for MySQL Flexible Server setup guide covers the database side in depth.

Set shell variables once to keep every command short:

RG="wp-prod-rg"
LOCATION="southeastasia"
PLAN="wp-prod-plan"
APP="wp-prod-site-$RANDOM"
MYSQL="wp-prod-mysql-$RANDOM"
ADMIN_USER="wpadmin"

Step 1: Create the Resource Group and App Service Plan – Deploy a Scalable WordPress Site on

The resource group holds everything; the App Service plan defines the compute tier. For production WordPress, start with P1v3 (Premium v3) — it supports autoscale, deployment slots, and always-on:

az group create --name "$RG" --location "$LOCATION"

az appservice plan create \
  --name "$PLAN" \
  --resource-group "$RG" \
  --location "$LOCATION" \
  --sku P1v3 \
  --is-linux

Linux plans are cheaper than Windows plans and run the official WordPress container image. The P1v3 SKU gives you 2 vCPU and 8 GB RAM per instance — plenty for a medium-traffic site, and you will add autoscale in Step 6.

Step 2: Provision Azure Database for MySQL Flexible Server

Never run MySQL on the same box as WordPress in production. Azure App Service pairs best with Azure Database for MySQL Flexible Server: automated backups, point-in-time restore, and independent scaling of compute and storage.

MYSQL_PASS="$(openssl rand -base64 24)"

az mysql flexible-server create \
  --name "$MYSQL" \
  --resource-group "$RG" \
  --location "$LOCATION" \
  --admin-user "$ADMIN_USER" \
  --admin-password "$MYSQL_PASS" \
  --sku-name Standard_B1ms \
  --tier Burstable \
  --storage-size 32 \
  --version 8.0 \
  --database-name wordpress \
  --public-access 0.0.0.0-255.255.255.255

The --public-access range above opens the firewall broadly for simplicity; tighten it to your App Service outbound IPs (find them with az webapp show --query outboundIpAddresses) before going live. Save $MYSQL_PASS in a vault — you will need it once more in Step 4.

Step 3: Create the Web App and Deploy WordPress

Create the web app with the official WordPress container image, then wire the database connection as app settings so WordPress picks them up automatically:

az webapp create \
  --name "$APP" \
  --resource-group "$RG" \
  --plan "$PLAN" \
  --deployment-container-image-name "wordpress:6-apache"

MYSQL_HOST="${MYSQL}.mysql.database.azure.com"

az webapp config appsettings set \
  --name "$APP" \
  --resource-group "$RG" \
  --settings \
    WORDPRESS_DB_HOST="$MYSQL_HOST" \
    WORDPRESS_DB_USER="${ADMIN_USER}@${MYSQL}" \
    WORDPRESS_DB_PASSWORD="$MYSQL_PASS" \
    WORDPRESS_DB_NAME="wordpress" \
    WORDPRESS_TABLE_PREFIX="wp_" \
    WEBSITES_ENABLE_APP_SERVICE_STORAGE="false"

Open https://$APP.azurewebsites.net and complete the famous five-minute WordPress install in the browser. Choose a strong admin password and a non-default admin username.

Step 4: Enable Always On and PHP Tuning

By default, idle apps are unloaded — fine for dev, terrible for production. Enable Always On and tune PHP for WordPress workloads:

az webapp config set \
  --name "$APP" \
  --resource-group "$RG" \
  --always-on true \
  --http20-enabled true \
  --min-tls-version 1.2

az webapp config appsettings set \
  --name "$APP" \
  --resource-group "$RG" \
  --settings \
    PHP_MEMORY_LIMIT="512M" \
    PHP_MAX_EXECUTION_TIME="300" \
    PHP_UPLOAD_MAX_FILESIZE="64M" \
    PHP_POST_MAX_SIZE="64M"

These settings raise the memory limit for page builders and media-heavy themes, and extend execution time for imports and updates. If you also serve static assets from object storage, the host a static website on Azure Storage guide shows how to offload them cheaply.

Step 5: Add Redis Object Caching

Database queries are the usual WordPress bottleneck. Azure Cache for Redis as an object cache cuts repeat queries dramatically:

az redis create \
  --name "${APP}-redis" \
  --resource-group "$RG" \
  --location "$LOCATION" \
  --sku Basic --vm-size c0

REDIS_KEY=$(az redis list-keys \
  --name "${APP}-redis" \
  --resource-group "$RG" \
  --query primaryKey -o tsv)

az webapp config appsettings set \
  --name "$APP" \
  --resource-group "$RG" \
  --settings \
    WP_REDIS_HOST="${APP}-redis.redis.cache.windows.net" \
    WP_REDIS_PORT="6380" \
    WP_REDIS_PASSWORD="$REDIS_KEY"

Then install the free Redis Object Cache plugin from the WordPress dashboard and enable it — it reads these constants automatically. Expect a 30–70% drop in database queries on typical pages.

Step 6: Configure Autoscale for Traffic Spikes

This is where Azure App Service earns its keep. An autoscale profile adds instances when CPU is high and removes them when traffic drops:

az monitor autoscale create \
  --resource-group "$RG" \
  --resource "$PLAN" \
  --resource-type Microsoft.Web/serverfarms \
  --name "${PLAN}-autoscale" \
  --min-count 2 --max-count 6 --count 2

az monitor autoscale rule create \
  --resource-group "$RG" \
  --autoscale-name "${PLAN}-autoscale" \
  --condition "CpuPercentage > 70 avg 5m" \
  --scale out 2

az monitor autoscale rule create \
  --resource-group "$RG" \
  --autoscale-name "${PLAN}-autoscale" \
  --condition "CpuPercentage < 30 avg 10m" \
  --scale in 1

Starting at two instances also gives you zone-redundant availability — a single instance failure no longer takes the site down. Pair this with deployment slots (below) for zero-downtime updates.

Step 7: Set Up Deployment Slots and Automated Backups

Deployment slots let you stage changes on a live URL before swapping them into production with no downtime:

az webapp deployment slot create \
  --name "$APP" \
  --resource-group "$RG" \
  --slot staging

# after verifying the staging slot:
az webapp deployment slot swap \
  --name "$APP" \
  --resource-group "$RG" \
  --slot staging \
  --target-slot production

Enable automated backups of the app (files + configuration) to a storage account — this complements the database's own point-in-time restore:

STORAGE="${APP//-/}backup"
az storage account create \
  --name "$STORAGE" \
  --resource-group "$RG" \
  --location "$LOCATION" \
  --sku Standard_LRS

SAS_URL=$(az storage container generate-sas \
  --account-name "$STORAGE" \
  --name app-backups \
  --permissions rwdl \
  --expiry 2030-01-01 -o tsv)

az webapp config backup create \
  --resource-group "$RG" \
  --webapp-name "$APP" \
  --backup-name "nightly-backup" \
  --container-url "https://${STORAGE}.blob.core.windows.net/app-backups?${SAS_URL}" \
  --frequency 1d --retain-one true
Azure App Service architecture with load balancer and database
Azure App Service architecture: load balancer, app instances, managed database, and backups.

Step 8: Harden the WordPress Installation

A scalable site is worthless if it gets compromised. Apply these hardening basics:

  • Force HTTPS only: az webapp update --name "$APP" --resource-group "$RG" --https-only true.
  • Disable XML-RPC and file editing via wp-config.php constants (DISALLOW_FILE_EDIT).
  • Restrict wp-admin with an access restriction rule allowing only your office IP.
  • Install a Web Application Firewall — Azure Front Door with managed WAF rules in front of Azure App Service blocks OWASP Top 10 attacks.
  • Keep WordPress core, themes, and plugins updated; use the staging slot to test every update first.

Troubleshooting Common Azure App Service WordPress Issues

Database connection errors after deploy

The usual cause is the MySQL firewall: confirm the App Service outbound IPs are allow-listed on the Flexible Server. Also verify WORDPRESS_DB_HOST uses the full .mysql.database.azure.com hostname and that SSL is required (Flexible Server enforces it).

Container fails to start / 502 errors

Check az webapp log tail --name "$APP" --resource-group "$RG" for the container output. Common culprits: wrong image tag, missing app settings, or the plan's storage quota being full on lower SKUs.

Slow admin dashboard

Admin pages bypass page caching by design. Verify the Redis object cache plugin reports "Connected", raise the plan SKU if CPU is saturated, and consider moving wp-cron.php to a real scheduled task so traffic spikes don't trigger cron stampedes.

Autoscale not triggering

Autoscale reacts to average CPU over the window you configured — a 5-minute spike may not move a 5-minute average enough. Lower the threshold, shorten the window, or add a rule on HTTP queue length for more responsive scaling.

Backup failures

Expired SAS tokens are the classic cause. Regenerate the SAS URL with a far-future expiry (as in Step 7) and update the backup configuration.

Conclusion

Deploying WordPress on Azure App Service replaces a fragile single VM with a managed, autoscaling platform: the App Service plan handles compute, Flexible Server handles MySQL with point-in-time restore, Redis handles caching, deployment slots handle zero-downtime updates, and automated backups protect you from disasters. The CLI commands above are idempotent enough to become your runbook — save them, version them, and redeploying the whole stack becomes a script instead of a weekend.

For the official reference on every setting used here, see the Microsoft Azure App Service documentation. And if you ever need a cheaper static front for marketing pages, you can host a static website on Azure Storage alongside your WordPress origin.

You may also like

KbLinux

Typically replies within a day

Hello, Welcome to the site. Please click below button for chatting me through Telegram.