How to Set Up a WordPress Blog in Microsoft Azure

Adam Listek

Adam Listek

Read more posts by this author.

Two of the most difficult aspects of running a modern website is managing the hosting environment and the backing database. Microsoft Azure offers two different products that can easily run a complex website. By using Azure Database for MySQL and Azure Web Apps, creating and running a WordPress site becomes easier.

In this article, we will run through all the steps necessary to create a simple WordPress site, using Azure Web Apps and Azure Database for MySQL.

There are many ways to host a site. Traditionally, this would be done via a LAMP stack (Linux, Apache, MySQL, and PHP). But why not use a virtual machine with that pre-installed set of software instead of Web Apps and managed MySQL?

With a traditional LAMP stack, there is the typical server administration that is necessary for performance and security. Therefore, you are not just spending time managing your site, you also need to keep the entire Linux operating system up to date, functioning well, and staying secure.

If we offload these tasks to Azure Web Apps and the Azure managed MySQL product, then we simplify the role of an administrator. This allows a website owner to focus on the site instead of all the hosting tasks.

Examples of using Web Apps, are to host a Ghost blog. In this article, we will use these products to create a solid and robust backend for the popular content management system (CMS) WordPress.

Azure Database for MySQL

Managing and optimizing databases is a difficult task. Oftentimes a website owner will need to spend much of their time making sure that the backend database is functioning and readily available.

The good news is. Azure has a managed MySQL service that simplifies these tasks. Using the following steps, we are going to provision a managed MySQL instance, create a MySQL database, and configure the instance for use with WordPress.

Provisioning the Azure Database for MySQL Resource

  1. Navigate to the Azure Database for MySQL servers section within the Azure Portal and click on Create Azure Database for MySQL server.
Azure Portal section to deploy a managed MySQL instance
Azure Portal section to deploy a managed MySQL instance

2. A form comes after to input the necessary information to provision the instance. Use the following values.

  • Resource Group: The chosen resource group will contain both the MySQL database and the Web App.
  • Server Name: Name the MySQL instance an appropriate name, which should reflect the environment and the instances purpose.
  • Location: The geographic location will help performance if located near where the majority of your websites traffic is originating from.
  • Version: In this article, we choose 8.0, as this is the latest version of MySQL available.
Entering necessary provisioning details for the MySQL instance
Entering necessary provisioning details for the MySQL instance

3. Next we will choose the Compute + storage size, which in this article, we are choosing the Basic tier with a single core.

Choosing the pricing tier for the MySQL instance
Choosing the pricing tier for the MySQL instance

If you want to create Read Replica’s (useful for scaling the reads, and load, across several machines), then choose a size from the General Purpose and Memory Optimized options. These are more expensive but offer more options and performance.

4. Next, define an administrative username (which acts as the root user of MySQL) and an appropriately complex password.

Entering the administrative username and password for the MySQL instance
Entering the administrative username and password for the MySQL instance

5. Tagging is useful for adding additional metadata to an Azure resource, but not necessary in this example.

The tagging section of the MySQL instance
The tagging section of the MySQL instance

6. Finally click on Create to start the process of provisioning the managed MySQL instance.

Reviewing the entered settings and creating the MySQL instance
Reviewing the entered settings and creating the MySQL instance

Once complete, you’re one step closer to your Azure WordPress blog!

Configuring the Azure MySQL Instance

There are important steps to ensure that Azure MySQL instance can communicate with the Web App. Following the steps also allow the creation of the necessary wordpress database that will be used to house our WordPress data.

Allowing the Necessary Traffic Through the Firewall

  1. Once the MySQL instance is provisioned, select the instance from the resources list, and navigate to the Connection security section. Once there, click on Add current client IP address.

We are making sure to add our client IP address to allow a third-party MySQL client to connect and create the necessary database. If you are doing this from a different client location, make sure to add that IP instead.

Allowing the client IP address through the MySQL firewall
Allowing the client IP address through the MySQL firewall

2. Next, we are going to Allow access to Azure Services, this will allow the Web App to communicate with this managed MySQL instance.

Allowing Azure Services through the MySQL firewall
Allowing Azure Services through the MySQL firewall

Connect to the Managed MySQL Instance and Create the WordPress Database

  1. Navigate to the Connection strings section as we will need to use the Server and Uid values to connect to our database.
Pulling the correct values from the Connection Strings screen of the MySQL instance
Pulling the correct values from the Connection Strings screen of the MySQL instance

2. In this article, we are going to connect via HeidiSQL, a Windows application for managing MySQL databases, to create the WordPress database. As you can see in the example below, we have entered the IP from the prior Server value and the User as the Uid value. The password used is the same as we originally created when provisioning the instance.

Entering the connection details into the HeidiSQL application
Entering the connection details into the HeidiSQL application

3. Next, navigate to the Advanced section and check, Use SSL, leaving all other values their default.

Checking, Use SSL, on the HeidiSQL connection details
Checking, Use SSL, on the HeidiSQL connection details

4. If the client side IP is correct, that was allowed through the firewall, and all other values are accurate, then the next pane should show the default databases that are created with a new MySQL server.

Verifying that the proper default databases show when connecting to the MySQL instance in HeidiSQL
Verifying that the proper default databases show when connecting to the MySQL instance in HeidiSQL

5. Right-click on the server, Unnamed in this example, and choose to Create new → Database.

Creating a new database in HeidiSQL
Creating a new database in HeidiSQL

6. Enter the name wordpress and choose the Collation of utf8mb4_unicode_ci, which is the preferred default for WordPress databases.

Entering the necessary WordPress database creation details in HeidiSQL
Entering the necessary WordPress database creation details in HeidiSQL

7. If the operation was successful, you will see a new wordpress database shown in the list.

If the operation was successful, you will see a new wordpress database shown in the list.
If the operation was successful, you will see a new wordpress database shown in the list.

If using a command line MySQL client, the code below is all that is necessary to create the same database.

CREATE DATABASE wordpress;

Azure Web App

Microsoft Azure Web App’s offer an application experience that greatly decreases the management required of a traditional hosting environment. For this example, we are going to use the container (Docker) based approach to our WordPress hosting environment.

Provisioning the WordPress Web App

  1. Navigate to the Azure Web App’s section and click on Create Web App. Next, we will fill in the necessary details to provision our instance.
  • Resource Group: Use the same resource group that the Managed MySQL instance was previously stored in.
  • Name: Use a descriptive name that easily identifies your web application.
  • Publish: Docker Container
  • Region: Choose the same region that the Managed MySQL instance was provisioned in to make sure that geographical distance does not hinder performance.
Creating the Azure Web App
Creating the Azure Web App

2. Next, we will choose the appropriate App Service Plan Sku. In this article, we are going to use the S1 Production instance.

Choosing the pricing tier for the Azure Web App
Choosing the pricing tier for the Azure Web App

3. After clicking Next: Docker, we will choose the following WordPress docker container to use as the basis for our web app.

  • Image Source: Docker Hub
  • Access Type: Public
  • Image and tag: wordpress
Entering the necessary Docker container details for the Azure Web App
Entering the necessary Docker container details for the Azure Web App

4. Due to the specific combination of choices made, Application Insights are not available for use in this Web App, therefore we can move on to Tags.

Showing that Application Insights are not available for this application
Showing that Application Insights are not available for this application

5. As before, with the Managed MySQL instance, we are opting not to tag these resources.

Opting to not add any additional tags to this Web App instance
Opting to not add any additional tags to this Web App instance

6. Finally, click on Create to provision the Web App.

Provisioning the Web App
Provisioning the Web App

You should now have a web app up and running. This web app will be your home base for your Azure WordPress blog.

Azure Web App Configuration

Now that the MySQL database is setup, as is the Web App, we can configure the two resources to talk to each other and finally install WordPress.

There are a few environmental configurations that work together with the WordPress container image to allow us to define what is necessary to connect the container to the MySQL database.

  • WORDPRESS_DB_HOST
  • WORDPRESS_DB_USER
  • WORDPRESS_DB_PASSWORD
  • WORDPRESS_CONFIG_EXTRAdefine( 'MYSQL_CLIENT_FLAGS', MYSQLI_CLIENT_SSL );

The reason that we are adding the additional configuration is to tell WordPress that we are using an SSL connection to connect to the database.

  1. Navigate to the newly provisioned Web App and the Settings → Configuration section.

2. We are going to add in the application settings as defined above, and as you can see below.

We are purposely not showing the WORDPRESS_DB_PASSWORD environmental variable, but this would also need to be entered.

Entering the WORDPRESS_DB_HOST in the application settings
Entering the WORDPRESS_DB_HOST in the application settings
Entering the WORDPRESS_DB_USER in the application settings
Entering the WORDPRESS_DB_USER in the application settings
Entering the WORDPRESS_CONFIG_EXTRA in the application settings
Entering the WORDPRESS_CONFIG_EXTRA in the application settings

3. You should see the following Application settings defined once all values have been entered.

Verifying all entered Application settings
Verifying all entered Application settings

4. After you click Save, the Web App will restart and use those settings when re-deploying the WordPress container image. Now onto actually installing WordPress in Azure.

Installing WordPress in Azure

The final steps will demonstrate that WordPress can actually function and work with the Azure Managed MySQL instance.

  1. Navigate to the public URL of your Web App.

2. On the first visit, if everything is functioning, you should be presented with the standard WordPress installation screen.

The choose language section of the WordPress installer
The choose language section of the WordPress installer

3. Enter the typical installation information and click on Install.

The standard WordPress installation details screen
The standard WordPress installation details screen

4. If the installation succeeded, you will see a Success page.

The success screen of the WordPress installer
The success screen of the WordPress installer

5. Finally, navigate to the public URL and the browser should now show the default theme and hello world placeholder text.

The default theme and homepage of the WordPress install
The default theme and homepage of the WordPress install

Conclusion

The creation of a Managed MySQL instance and Web App is not that taxing. The abilities and ease of administration make this an extremely compelling combination. With MySQL instance’s ability to easily add Read Replica replication instances (with the correct instance type), scalability becomes easier than ever to manage. This will work for many different CMS applications that can use MySQL and a standard web server Docker container!

Subscribe to Adam the Automator

Get the latest posts delivered right to your inbox

Looks like you're offline!