page_type: sample languages:
App Templates are packaged app samples designed to reduce the time it takes a developer to deploy their code to Azure. Unlike standalone example code, the goal of App Templates is to provide all the components to deploy an app to Azure with automation via GitHub Actions or other CI/CD services.
This specific sample consists of example code, CI/CD components, and documentation containing all the required steps to deploy a fully functional worspress site and is designed to be compatible with the Azure Developer CLI(azd) which is currently in preview.
The purpose of App Templates is to deliver and prove the value of accelerated onboarding for developers who are new to Azure.
Refer to the App Templates repo Readme for more samples that are compatible with Azure Developer CLI (azd)
Overview
WordPress (WP or WordPress.org) is a free and open-source content management system (CMS) written in PHP and paired with a MySQL or MariaDB database. Features include a plugin architecture and a template system, referred to within WordPress as "Themes". WordPress was originally created as a blog-publishing system but has evolved to support other web content types including more traditional mailing lists and Internet fora, media galleries, membership sites, learning management systems (LMS) and online stores. One of the most popular content management system solutions in use, WordPress is used by 42.8% of the top 10 million websites as of October 2021.
To function, WordPress at minimum has to be installed on a web server and connect to a mySQL database. So, to deploy Wordpress in Azure a number of different Azure services can be used: AKS, Virtual Machines, and App Service. For a full list of WordPress options on Azure, see WordPress on Azure Marketplace.
In this application template, you'll learn how to and will be able to easily, quickly create and deploy your first scalable and secure WordPress site to Azure, leveraging Azure Container Apps with Azure Database for MariaDb. This app template uses a number of Azure resources, and incurs a cost for your Azure Subscription. For pricing, visit Azure pricing calculator.
az account show
Below are benefits and potential extension scenarios for the solution.
Other potential extensions of this architecture are:
You can deploy this app template either using the Azure Developer CLI (azd) or the github pipeline provided.
Install Azure Developer CLI
Login to azure from your terminal. You can do this by running the following command:
azd auth login
Create and navigate into an empty directory
Clone the repository and initialize the app by running the following command:
azd init -t apptemplate-wordpress-on-aca
Once the command has finished
A file named azure.yaml is created in the root of your project.
Note: The file is already in the repository.
Deploy the ifrastructure by running the following command:
azd provision
This will start the Azure infrastructure provisioning process. Durring this process you will be asked to provide the following information:
deployWithRedis: Whether to deploy the solution with a Redis container or not.
Fork the repository
Fork the repository by clicking the 'Fork' button on the top right of the page. This creates a copy of the repository in your Github account for you to work in.
Create an Azure Service Principal
The newly created GitHub repo uses GitHub Actions to deploy Azure resources and application code automatically. Your subscription is accessed using an Azure Service Principal. This is an identity created for use by applications, hosted services, and automated tools to access Azure resources. The following steps show how to set up GitHub Actions to deploy Azure applications
Create an Azure Service Principal with contributor permissions on the subscription. The subscription-level permission is needed because the deployment includes creation of the resource group itself.
login interactively to azure using the following command:
az login --scope https://graph.microsoft.com//.default
Run the following az cli command, either locally on your command line or on the Cloud Shell. Replace {app-name} {subscription-id} with the id of the subscription in GUID format.
az ad sp create-for-rbac --name {app-name} --role owner --scopes /subscriptions/{subscription-id} --sdk-auth
The command should output a JSON object similar to this:
{
"clientId": "<GUID>",
"clientSecret": "<GUID>",
"subscriptionId": "<GUID>",
"tenantId": "<GUID>",
"activeDirectoryEndpointUrl": "<URL>",
"resourceManagerEndpointUrl": "<URL>",
"activeDirectoryGraphResourceId": "<URL>",
"sqlManagementEndpointUrl": "<URL>",
"galleryEndpointUrl": "<URL>",
"managementEndpointUrl": "<URL>"
}
store this information as it will be used in the next step.
Store the following values as GitHub Actions secrets
Repeat the above steps for the following secrets:
You will need to provide the following values as repository secrets to be used by the GitHub Actions workflow.
Store the following values as GitHub Actions variables
You will need to provide the following values as repository secrets to be used by the GitHub Actions workflow.
Execute the azure-dev.yml action workflow
After deployment, below resources will be created
Since this is a brand new Wordpress site, you will need to complete the initial setup which creates the Database schema and populates it with seed data as well as creates the wp-config.php
file to read the configuration from the environment variables.
To do this, you will first need to map the FQDN of the site you specified when provisioning the template to the public IP address of the Azure Application Gateway. You can do this by either adding an entry to your pubcic dns zone or simply by adding an entry to your hosts file.
Once you have mapped the FQDN to the public IP address, you can navigate to the site in your browser and complete the initial setup.
Navigate to the http://FQDN using your browser
Select the wordpress language and click Continue
Fill in the site title, the administrator username, password, and email address and click Install WordPress
Now you can navigate to the site in your browser and login using the username and password you specified during the setup to access the administration console or navigate to the site to see it.
When you are done, you can delete all the Azure resources created with this template by running the following command:
resourceGroup=<RESOURCE GROUP NAME>
az group delete --name $resourceGroup
or if you deployed using the azd cli
azd down
This project may contain trademarks or logos for projects, products, or services. Authorized use of Microsoft trademarks or logos is subject to and must follow Microsoft's Trademark & Brand Guidelines. Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship. Any use of third-party trademarks or logos are subject to those third-party's policies.