Deploy WordPress to Azure Web App for Container
Summary
Here are the instructions for creating a quick WordPress app and pushing the app to Azure Web App for Containers.
Detailed instructions can be found here.
Web App for Containers
Azure Web App for Containers is great for hosting front-end web applications.
The Docker file used to create this docker image is as follows:
version: '3.3'
services:
db:
image: mysql:5.7
volumes:
- db_data:/var/lib/mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: somewordpress
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress
wordpress:
depends_on:
- db
image: wordpress:latest
ports:
- "8000:80"
restart: always
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress
volumes:
db_data:
Create Azure Resources
- Resource Group
- App Service Plan
Create a new directory to temporarily store data.
mkdir tutorial
cd tutorial
git clone https://github.com/Azure-Samples/multicontainerwordpress
cd multicontainerwordpress
Create the Resource Group.
az group create --name RGContainers --location "UK South"
az appservice plan create --name ContainerAppServicePlan --resource-group RGContainers --sku S1 --is-linux
Create the Docker Compose app
az webapp create --resource-group RGContainers --plan ContainerAppServicePlan --name eaxwordpress01 --multicontainer-config-type compose --multicontainer-config-file docker-compose-wordpress.yml
Browse the app: http://eaxwordpress01.azurewebsites.net
This has created two resources; App Service Plan and a Web App.
Connect to MySQL Server
Create the MySQL Server
az mysql server create --resource-group RGContainers --name eax360mysqserver --location "South Central US" --admin-user adminuser --admin-password My5up3rStr0ngPaSw0rd! --sku-name B_Gen5_1 --version 5.7
Create firewall rules
az mysql server firewall-rule create --name allAzureIPs --server eax360mysqserver --resource-group RGContainers --start-ip-address 0.0.0.0 --end-ip-address 0.0.0.0
Create a MySQL database
az mysql db create --resource-group RGContainers --server-name eax360mysqserver --name wordpress
Add WordPress database variables
az webapp config appsettings set --resource-group RGContainers --name eaxwordpress01 --settings WORDPRESS_DB_HOST="eax360mysqserver.mysql.database.azure.com" WORDPRESS_DB_USER="adminuser@eax360mysqserver" WORDPRESS_DB_PASSWORD="My5up3rStr0ngPaSw0rd!" WORDPRESS_DB_NAME="wordpress" MYSQL_SSL_CA="BaltimoreCyberTrustroot.crt.pem"
Create the SSL certificate
az webapp config container set --resource-group RGContainers --name eaxwordpress01 --multicontainer-config-type compose --multicontainer-config-file docker-compose-wordpress.yml
Browse the app: http://eaxwordpress01.azurewebsites.net
Add Persistent Storage
Configure environment variables
az webapp config appsettings set --resource-group RGContainers --name eaxwordpress01 --settings WEBSITES_ENABLE_APP_SERVICE_STORAGE=TRUE
Update with new configurations
az webapp config container set --resource-group RGContainers --name eaxwordpress01 --multicontainer-config-type compose --multicontainer-config-file docker-compose-wordpress.yml
Browse the app: http://eaxwordpress01.azurewebsites.net