Setting Up A Distributed Load Balanced Enterprise WordPress Website

Clarity eCommerce - The eCommerce Platform to Scale and Grow Your Business
Setting Up A Distributed Load Balanced Enterprise WordPress Website

Step-by-Step Walkthrough of Distributed Load Balancing in WordPress

Often, we're faced with the question of whether WordPress can support the digital needs of an enterprise company. To answer the question, we'll say yes, and that's because of a host of factors, which include scalability, flexibility, ongoing support from the platform, and a few others. However, there are also a lot of challenges that one would encounter when using WordPress to meet the needs of the enterprise.

One of the often faced challenges of an enterprise WordPress is the load speed and performance. To start with, I'm sure you don't need anybody to tell you how important a load speed is to your website. At least, you know the frustration attached to using a website with low load speed. So, the burning question is, what are the factors that lower the performance level of an enterprise WordPress website, and how can one avoid them?

5 Reasons You Should Seek the Best WordPress Upgrade Specialists to Help You Update WordPress Manually

Let's face it! Several factors can make that happen. One of them is having a high traffic site and servers, with not enough capacity to handle more users. In this case, when proper measures are not put in place, the server gradually goes down from the traffic, ending up becoming unavailable. In a way to avoid that from happening, one of the things you can do as an enterprise WordPress website owner is to introduce a load balancer.

Laying the Groundwork before we dive in

What Is Web Server Load Balancing?

By definition, the term 'load balancing' is the process of sharing network traffic across multiple web servers. Furthermore, the main reason is to ensure that none of the servers in use are getting too much load than their capacities. In case you don't know, there are lots of benefits attached to setting up a load balancer for your enterprise WordPress. Let's have a quick look at some of them below:

  • First, a load balancer helps to manage how information flows from an enterprise WordPress server to endpoint devices, including smartphones, tablets, and PCs.
  • Apart from that, load balancers also help web servers to efficiently move data, preventing overload.
  • Furthermore, load balancers help to perform health checks on enterprise WordPress servers, identifying whether or not they are capable of handling data requests. Also, in the case where there are unhealthy WordPress servers, a load balancer can help to remove them. That can go on and on until they are restored.

Having talked about the benefits of web server load balancing, what's next is to have a quick look at its methods.

defining the parameters and methods

Web Server Load Balancing Algorithm and Techniques

A load balancer usually follows an algorithm to identify how requests are distributed across various servers. There are plenty of options available to use, ranging from simple to very complex techniques.

  • Least Response Time Method
    The Least response time is a load balancing method used to direct traffic to a web server with the lowest response time (on the average) and the least active connection.
  • Least Connection Method
    Unlike the least response time method, this load balancing technique only directs traffic to a web server with the least active connection.
  • Round Robin Method
    Just like its name, this load balancing algorithm helps to direct traffic to the first available server, upon rotation. The interesting thing, however, is that any server that receives the traffic automatically rotates to the bottom of the queue. This method will be the best option when you have servers with equal specs.
  • Source IP Hash
    Source IP hash is a load balancing technique that takes the source and destination IP address of client and web server, combining them to generate a hash key. Speaking of the key, it identifies the eligible server to receive a request.
  • URL Hash
    URL Hash is a technique of load balancing that helps to evenly distribute writes across multiple WordPress sites. Apart from that, it also helps to send all reads to the websites owing to the object.
How To Set Up A Load Balancer Using Two Web Servers And One Database

Configuring Servers & Databases

In this post, we'll be making use of MariaDB (database), Scaleway managed Load Balancer, and two WordPress servers. So, to get started, you need to create an account with Scaleway by clicking here.

Now, it's time to configure the load balancer. Check below for the step by step guide on how to do it:

  • The first thing after logging in is to Create a Load Balancer for WordPress. You'll be able to do that by heading to the Scaleway menu and clicking on Load Balancer.
  • After that, you'll have to enter the Name of the Load Balancer. After that, the next thing is to select a Region for it. It's worth noting that you have to choose the same region as your instances. By so doing, you'll automatically get a new IP address.
  • Next, you need to create a frontend rule for the load balancer. So, to configure your frontend, choose "80" for the port and "wordpress-frontend-rule" as its name.
  • What is next is to configure the backend rule for your load balancer? To do that, you have to configure the following parameters:
    • Backend name: You need to choose an appropriate name, like "wordpress-backend-rule", for your backend.
    • Protocol: To gain access to the HTTP features of the load balancer, you need to set your protocol as "HTTP".
    • Port: The value for your port may differ, depending on what you use for your connection. In the case of standard configuration for the web application, it's port 80. However, in the case there's an SSL to encrypt backend connections, you'll have to use "443" as your port value.
    • Health Check Type: Set your health check type to "HTTP".
    • URI: For your uniform resource identifier set up, all you need is to set it as "/".
    • Code: As for the code, this is what the Nginx web server sends with each response. So, you'll have to set the value as "200".
    • Proxy And Sticky Session: Both features are not needed for this setup, so leave them disabled.
    • Server IPs: To the list of backend servers, you need to add two WordPress instances, including 10.45.2.3 and 10.45.2.4.
  • Lastly, you have to deploy the Load Balancer by clicking on "Create a Load Balancer".
Configuring your website for distributed load balancing

Configuring WordPress

The essence of this process is to enable the instances to bypass the local database and utilize the dedicated MariaDB instance. That said, to configure your enterprise WordPress, follow the following straightforward steps below:

  • To get started, you need to first connect to the instance. You'll be able to do that by connecting via SSH as "root".
  • Next, go to your files and open "var/www/wp-config.php" in your text editor. After doing that, all that you need to do is edit the database section as seen below:

// ** MySQL settings - You can get this info from your web host ** //

/** The name of the database for WordPress */ define('DB_NAME', 'wordpressdb');

/** MySQL database username */ define('DB_USER', 'wordpress');

/** MySQL database password */ define('DB_PASSWORD', '[yoursecretpassword]');

/** MySQL hostname */ define('DB_HOST', '10.46.5.6'); #IP of the MariaDB instance

/** Database Charset to use in creating database tables. */ define('DB_CHARSET', 'utf8');

/** The Database Collate type. Don't change this if in doubt. */ define('DB_COLLATE', '');

  • After that, save the file and close the text editor. It's worth noting that you'll only be able to get the content from the database of the MariaDB server when connecting to the instance via a web browser.
  • Next, go to your enterprise WordPress Admin interface, log in, and head to the Setting option to begin the configuration process.
    • WordPress Address (URL) enter the IP of one of the WordPress instances above.
    • Site Address (URL) enter the Load Balanced IP (51.51.51.51). You can also enter your domain name in the field, instead of the IP address. Don't forget to save the configuration after this step.
  • Next, run the same configuration steps for the second instance.
  • Lastly, enter the Load Balanced IP or the domain name in your browser to check your enterprise WordPress configuration.

Related Posts