WebsitesWordPress

How to create a High Availability Network for a blog or website

High availability is a way to provide redundancy to a blog, website or application. The most popular way to achieve this is by creating your own Cloud network. This is complex and expensive. You must have a minimum of three dedicated servers, some network-attached storage and advanced networking skills. However, you can create a High Availability network for blogs and websites over VPS servers. This vastly reduces the costs.

Because this method does not include network-attached storage, if your content changes a lot on your website, you must consider how these changes will be replicated to your network. We are using lsyncd to sync content over the cluster. This isn’t the best way to achieve high availability and shouldn’t be used on production/enterprise websites. See how to set up a MariaDB Galera Cluster to configure a professional high-availability solution. In this article, we are using Cloudflare to route the connections. This means we are not going to be setting up an SSL on each host but we do explain how to complete this. In our High Availability Blog network we have;

As we already have a cloud running. One of the VPS Servers is running on our cloud because this will be used as our HAProxy server. We will configure this in the next article. We’re assuming you either have an Internal MySQL server or a Remote MySQL server. You may not need a database server depending on your requirements.

Contents

  1. How to create a High Availability Network (This Page)
  2. How To Install Lsyncd Sync and sync data
  3. Set up HAProxy Server to load balance

Configure Backend Servers

On your High Availability network, Backend servers are the units that will house your websites or application files. In these guides, we are using the blog.f2h.cloud name. We need to install Apache and PHP on two of our VPS servers. We’re using Ubuntu 22.04 because that’s an LTS version. Let’s start.

Install Apache & PHP 8.1

Run the commands to install Apache and PHP 8.1. We are also going to install PHP-FPM.

ufw disable
apt install apache2
apt install software-properties-common
add-apt-repository ppa:ondrej/php
apt update
apt install php8.1 libapache2-mod-php8.1
systemctl restart apache2
apt install php8.1-zip php8.1-yaml php8.1-xmlrpc php8.1-soap php8.1-mysql php8.1-memcached php8.1-memcache php8.1-mcrypt php8.1-mbstring php8.1-imagick php8.1-enchant php8.1-curl php8.1-bz2 php8.1-xml php8.1-gd

You can see we have installed a number of modules to work with PHP. That’s because our backend servers are going to be housing a WordPress website. You can search for more modules using apt search php8.1-*.

We also want to install PHP-FPM so

a2dismod php8.1 mpm_pre
a2dismod mpm_prefork
a2enmod mpm_worker
a2enmod proxy
a2enmod proxy_fcgi
a2enmod setenvif
a2enmod rewrite
apt install php8.1-fpm
a2enconf php8.1-fpm
systemctl enable php8.1-fpm.service
systemctl start php8.1-fpm.service
systemctl restart apache2

You can configure the values for PHP-FPM in the /etc/apache2/mods-available/mpm_worker.conf file.

Configure Apache

Now we need to configure Apache to work with our domain name. In this example, we are using the blog.f2h.cloud subdomain. First, create the file that will hold the details of our domain.

nano /etc/apache2/sites-available/blog.f2h.cloud.conf

Inside the file, we specify the correct values. Change the values and save the file. We are not using SSL on our backend servers because that will be handled by Cloudflare.

<VirtualHost *:80>
    ServerName blog.f2h.cloud
    ServerAlias www.f2h.cloud
    ServerAdmin [email protected]
    DocumentRoot /var/www/blog.f2h.cloud/public_html

    <Directory /var/www/blog.f2h.cloud/public_html>
        Options -Indexes +FollowSymLinks
        AllowOverride All
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/blog.f2h.cloud-error.log
    CustomLog ${APACHE_LOG_DIR}/blog.f2h.cloud-access.log combined
</VirtualHost>

Enable the configuration and restart Apache. Don’t forget to specify the name of your configuration file.

a2ensite blog.f2h.cloud.conf
service apache2 restart

Now you can move your files to the location you specified in the Apache configuration file above. In our example, our files would be located at /var/www/blog.f2h.cloud/public_html. If you were to update the A record for your domain now. And if you have a public IP, it should start resolving from the server you have just created. If you are using Cloudflare like us, the connection is automatically secured.

You would now repeat the process exactly for the rest of your backend servers. We are just going to duplicate the server we have just configured to create two identical servers. In the next article, we will Install LSYNCD to sync data from our FR server to our UK server and in the final article, we will set up HAProxy server to load balance and provide high availability.

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button