In the previous tutorial, you learned how to create a temporary failover server using Nginx Proxy Manager.
Initially, you migrated your database from your production server (local WordPress docker container) to a WordPress web server in cPanel via a Migrate Guru plugin.
However, Migrate Guru only allowed you to migrate your servers 5 times a month. To bypass that limit, the WPvivid backup plugin will be used in this article.
Moreover, Lsycd will synchronize between the backup files on the local WordPress docker volume and your cPanel WordPress Webdav drive.
Prerequisite: You have mounted a WebDAV drive on your local machine (production site).
Step 1: Log in to your local WordPress site via https://yourdomain/wp-admin and install a plugin called WPvivid backup.
Step 2: Find out the name of your WordPress docker container by
sudo docker ps
In my case, it is wordpress-1.
Step 3: Enter your local WordPress container shell by
sudo docker exec -it wordpress-1 bash
Go to the root directory cd / Find the wp-content folder by
find . -name wp-content
In my case, it is /var/www/html/wp-content Enter exit to quit the WordPress container shell.
Step 4: Find out your WordPress docker volume on your local machine by
sudo docker inspect -f '{{ .Mounts }}' your_docker_container
In my case, it is sudo docker inspect -f ‘{{ .Mounts }}’ wordpress-1
[{volume 0d31546f50d5a9e9383037022758fa807404a26503c8d892fbec892104bb4513 /var/lib/docker/volumes/0d31546f50d5a9e9383037022758fa807404a26503c8d892fbec892104bb4513/_data /var/www/html local true }]
or
If you are using Portainer, you may go to the container section. Press the Duplicate / Edit button and then find out the WordPress volume.
In my case, the location is /var/lib/docker/volumes/0d31546f50d5a9e9383037022758fa807404a26503c8d892fbec892104bb4513/_data.
Step 5: Check the owner and owner group of the WordPress container volume with the following script.
Replace /var/lib/docker/volumes/0d31546f50d5a9e9383037022758fa807404a26503c8d892fbec892104bb4513/_data with your WordPress container volume location.
sudo ls -l /var/lib/docker/volumes/0d31546f50d5a9e9383037022758fa807404a26503c8d892fbec892104bb4513/_data/wp-content/
In my case, the volume belongs to www-data:www-data.
Step 6: To modify the failover site quickly, you may need to bypass your DNS resolver temporarily (similar to DNS poisoning).
If you have two PCs, you may use one to resolve your WordPress domain typically and another with DNS poisoning to configure two WordPress simultaneously.
On Windows 10, edit C:\Windows\System32\drivers\etc\hosts with admin rights.
Add your_ip your_domain to the list and save. On Ubuntu 22.04,
sudo nano /etc/hosts
Add your_ip your_domain to the list and save. Another way is to change the IP of your WordPress domain to the cPanel WordPress (failover) site if you have a working Nginx Proxy Manager.
The slowest way is to change your WordPress domain record on Cloudflare. It may take a long time to propagate your new DNS record.
The concept of this step is complicated, but once you know the tricks, it will be pretty helpful for you.
Step 7: WPvivid requires around 1G of RAM to function properly. Edit the wp-config.php on your cPanel File Manager, add the following line.
ini_set('memory_limit','1G');
Save Changes Top right corner.
Step 8: Log in to your cPanel WordPress (failover) site via https://yourdomain/wp-admin.
Step 9: Install WPvivid Backup Plugin on your cPanel WordPress site.
It means the WPvivd Backup plugin will be installed on both your servers (production & failover server).
Step 10: Install a library called lsyncd. It will synchronize the WPvivid backup between your local WordPress and cPanel WordPress (failover).
sudo apt install lsyncd -y
Step 11: Edit the lsyncd service configuration.
sudo nano /etc/init.d/lsyncd
Add a line USER=your_volume_owner where your_volume_owner is the user you obtained from step 3.
In my case, it is,
USER=www-data
PATH=/sbin:/usr/sbin:/bin:/usr/bin
DESC="synchronization daemon"
NAME=lsyncd
DAEMON=/usr/bin/$NAME
CONFIG=/etc/lsyncd/lsyncd.conf.lua
PIDFILE=/var/run/$NAME.pid
DAEMON_ARGS=" -pidfile ${PIDFILE} ${CONFIG}"
SCRIPTNAME=/etc/init.d/$NAME
NICELEVEL=10
Ctrl + X to save the file.
Step 12: Find out the wp-content location of your web disk.
cd /media/webdav
find . -name wp-content
In my case, it is /media/webdav/test.silicon.blog/wp-content.
Step 13: Create a configuration file for lsyncd. At this moment, you will only synchronize the WordPress theme.
sudo mkdir /etc/lsyncd
sudo nano /etc/lsyncd/lsyncd.conf.lua
Replace your_local_wordpress_volume_wp_content_location with the result you obtained from step 5 and
sync {
default.direct,
source = "your_local_wordpress_volume_wp_content_location/themes",
target = "your_cpanel_wordpress_volume_wp_content_location/themes"
}
In my case, it is
In my case, it is
sync {
default.direct,
source = "/var/lib/docker/volumes/0d31546f50d5a9e9383037022758fa807404a26503c8d892fbec892104bb4513/_data/wp-content/themes",
target = "/media/webdav/test.silicon.blog/wp-content/themes"
}
Press Ctrl + X to save the file.
Step 14: Enable and start lsyncd on start by
sudo systemctl enable lsyncd
sudo systemctl start lsyncd
Step 15: Switch your DNS back to your local WordPress site, and try to delete or add some themes.
In my case, I deleted all the unused themes.
Switch the DNS back to the cPanel WordPress (failover) site. After some time, its theme will also be synchronized.
Step 16: Modify the lsyncd configuration to synchronize your WPvivid backup.
sudo nano /etc/lsyncd/lsyncd.conf.lua
sync {
default.direct,
source = "/var/lib/docker/volumes/0d31546f50d5a9e9383037022758fa807404a26503c8d892fbec892104bb4513/_data/wp-content/wpvividbackups/"
target = "/media/webdav/test.silicon.blog/wp-content/wpvividbackups/",
}
Restart the lsyncd service by
sudo systemctl restart lsyncd
Step 17: Switch your DNS back to your local WordPress site again (You will save a lot of time if you have two PCs, as mentioned in step 6).
Go to the WPvivid Backup plugin, and create a local backup file.
Step 18: Switch your DNS to your cPanel WordPress (failover) site.
Press the Scan uploaded backup or received backup on the WPvivid Backup plugin. If everything works properly, your failover site will have a backup file.
Step 19: Restore the backup.
Congratulation, your local machine and cPanel (failover) WordPress site WPvivid backup will synchronize automatically. There is no simple solution to create a failover site for WordPress automatically.
However, using this method, you can create a backup on your local machine (production site) and restore it on your failover site with one click (DNS poisoning is also needed XD).
This article may provide a workaround to manually create a failover site if you update your WordPress site infrequently, like me. If you are a hardworking content creator, my solution may not fit you as you must frequently restore your site.
I can’t find a similar solution on the market, so I am probably the first to invent and publish such a weird solution.
Creating a master-slave connection between the MYSQL database is feasible, but I want to avoid opening port 3306 to the public internet. Feel free to tell me another method to form a failover site using cPanel.
Check out this article if you want to enable HTTPS (install SSL certificate on your Apache server) on your WordPress docker container.