WordPress is perfectly suited for a small business to target customers in their specific market or location to reach customers across the globe, at any time, on any device.
But can it be a valid option for an enterprise or a startup with good ambitions?
Can it satisfy more advanced capabilities like extensibility, interoperability, and scalability that enterprise-grade software generally has?
More than most organizations, enterprise businesses need to maintain a scalable and reliable web presence to remain competitive. To that end, many IT leaders of large-scale organizations have historically looked to expensive web solutions requiring proprietary support contracts to guarantee quality.
There may be another way, though.
What is WordPress? WordPress is an open-source content management system (CMS) licensed under GPLv2 CMS, with more than 10 years of development. At its core, WordPress is the simplest, most popular way to create your own website or blog. In fact, WordPress powers over 37.6% of all the websites on the Internet.
Given the popularity of WordPress, I won’t dive too much into it as it is not the scope of this article.
So, what is the scope of this article? This article will show how to deploy WordPress on a High-Available cloud solution that will support horizontal scaling (this means that the number of machines can dynamically change based on the workloads your servers are experiencing). It will be based on the popular LAMP (Linux, Apache, MySQL, and PHP) stack and it will be modular so each component will be decoupled and highly available.
We will deploy everything on Oracle Cloud Infrastructure for many reasons that you can find here.
The final architecture will look like the one in the picture below.
Too complicated? Let’s break it down piece by piece.
A load balancer acts as the “traffic cop” sitting in front of your servers and routing client requests across all servers capable of fulfilling those requests in a manner that maximizes speed and capacity utilization and ensures that no one server is overworked, which could degrade performance. If a single server goes down, the load balancer redirects traffic to the remaining online servers. When a new server is added to the server group, the load balancer automatically starts to send requests to it.
You have many options at your disposal, and an extensive overview of the load balancer options is not the scope of this article. But one thing worth mentioning is that a load balancer is identified by its maximum capacity (bandwidth) for ingress plus egress traffic (10,100,400,8000 Mbps) and its routing policy (Weighted Round Robin, IP Hash, Least Connections).
Virtual Cloud Network
A virtual cloud network (VCN) is a customizable and private network in Oracle Cloud Infrastructure. Just like a traditional data center network, the VCN provides you with complete control over your network environment. This includes assigning your own private IP address space, creating subnets, route tables, and configuring stateful firewalls.
As you can see, there are two subnets, the public one in which we will put the WordPress machines and the Private one in which we will put the machine with MySQL.
NOTE 1: This is not the only possible architecture and there are other variations of this architecture that are equally valid if not better.
Availability Domains (AD)
An Oracle Cloud Infrastructure availability domain is:
“One or more data centers located within a region. Availability domains are isolated from each other, fault-tolerant, and very unlikely to fail simultaneously. Because availability domains do not share infrastructure such as power or cooling, or the internal availability domain network, a failure at one availability domain is unlikely to impact the availability of the others. All the availability domains in a region are connected to each other by a low latency, high bandwidth network.”
When you use multiple availability domains for an application stack, distributing instances across geographically separated availability domains provide application primary redundancy.
Oracle Cloud Infrastructure has created a new powerful approach that launches and manages identical VM instances in a logical group called an Instance Pool. The pool automatically provisions a horizontally scalable pool of VM instances. An Instance Pool uses an instance configuration template that contains all the settings for how you want an instance created. Instance Pools manage the launching of identical instances based on the instance configuration template. The pool maintains your configured instance count and can be updated to scale on demand. The Instance Pool constantly monitors its own health state to ensure all instances are in a running state. In the event of any instance failure, the pool will automatically self-heal and take corrective action to bring the pool back to a healthy state.
This will allow us, together with an Autoscaling policy, to scale dynamically based on the workloads of the machines inside the pool. The pool can shrink and grow based on a fixed schedule or a workload policy but we will talk about this later.
Again, I won’t discuss which is the best database for WordPress but I will go by popularity: MySQL.
I addition, later this year MySQL will be available as a managed service on Oracle Cloud so, to enhance the power of this solution, you can just migrate to MySQL as Service and get all the advantages of managed service without having to rebuild everything from scratch.
Let’s put our hands to work!
Step 0: Getting Started
As a prerequisite, you will need access to an Oracle Cloud account (if you don’t have it you can sign up for a free trial here).
To begin with, I won’t reinvent the wheel but instead, I will build on top of the great work made on lefred.be. Here you can get started on installing WordPress and MySQL and setting up a basic environment.
You should have something like this:
Let’s call awp3 the VM with WordPress installed and wp3mysql the VM with MySQL installed.
Step 1: Create your customised soldier
The first thing we will need to do is create a Template machine in which we will install and configure all the services that the machine will run. Later, the Instance pool will create an army of machines that will look exactly as the Template.
So, we kind of already have our Template machine ready (awp3), the only thing we need to make sure is that all the services will start at login. To do this just run:
sudo systemctl enable mysqld
sudo systemctl enable httpd
Ok so our base machine is ready so let’s create first a Custom Image and then an Instance Configuration.
So, from the Oracle Cloud Console-> Compute -> Instances -> Instance Details (by clicking on the instance) and then Create Custom Image first and then Create Instance Configuration as shown in the following pictures.
Step 2: Create the Load Balancer
To distribute the traffic between our army of machines we will need a load balancer.
To create one, from Oracle Cloud Console click on the left menu
Networking -> Load Balancer -> Create a Load Balancer as shown in the pictures.
Important: on the second page, make sure you click on “Show Advanced Options” and give a name to the backend set. We will use it later.
Note: You can customize the Load Balancer as you wish, I just used the standard settings and selected the HTPP Protocol for simplicity.
Step 3: It’s time to create an army
It’s time to create the Instance Pool, so again from the Oracle Cloud Console -> Compute -> Instance Configurations and select the Instance Configuration you created at Step 1. You can now click the button Create Instance Pool.
Here is where we assemble everything we built up until now.
Select the number of instances that will be in your pool (we are creating a static pool now and then we will add an Autoscaling Configuration to make it dynamic).
Select “Attach a Load Balancer” and select the Load Balancer you previously created with the corresponding Backend Set and finally select the port 80.
In the last part, you can choose where to allocate the resources you can distribute them across Fault Domains and Availability Domains to improve the resiliency of your application.
More info here
Step 4: Let’s make this army grow!
Ok so now we have our pools of instances running our front-end (you can make sure by visiting the Load Balancer’s IP Address) but the number of instances is fixed.
Let’s change that by navigating to Compute -> Instance Pools from Oracle Cloud Console and select the instance pool you just created. As shown in the image below, click on Create Autoscaling Configuration.
Select the Instance Pool as shown in the image and click next.
On the second page you can customize the behavior of your instance pool: choose Metric-base Scaling if you want your pool to adapt based on some metrics (CPU or Memory utilization) or Scheduled-based autoscaling if you want to change the size of your pool based on date and time.