Server security is the topmost priority for every system administrator. Besides having third-party security tools like Firewall, DDoS protection, etc. it is extremely important to keep every piece of code up-to-date on your production server.
When your application is in production, upgrading it is riskier. If your server is powered by Linux, Linux distributions keep releasing new versions every now and then. Each major release contains bug fixes, security updates, and new tools.
Upgrading a production server without any preparation is a big mistake. An unprepared upgrade can cause permanent data loss, poor server performance, and customer loss. In this article, I will list some important steps to take before initiating a server upgrade.
Things to do before upgrading a production server
Just recently I upgraded one of my clients’ server and it was a Ubuntu server. His e-commerce website receives a decent amount of traffic and has been around for almost a year now.
I decided to upgrade his server from Ubuntu 18.04 to 20.04 LTS. The actual upgrade took about 30 minutes but the preparation took longer. As a result, the upgrade was smooth without any downtime.
Prepare full backup
Backing up just the website or the entire server should be the daily task. Before upgrading, make sure your website is fully backed up in the cloud or locally. Recently, I listed some of the greatest backup plugins for WordPress. If your website is powered by WordPress, read the article best backup plugins for WordPress.
If you are using any other CMS, create a backup of the application. If you are using cPanel based web hosting, there should be an option to create a full backup of the entire server. Creating full backup from cPanel is the easiest way.
If you are using any of the cPanels that I have covered in my cPanel series, they all have options to create a full backup. All of these Linux cPanles are free and open source. Just let me know if you have any trouble with anyone of the cPanels I have reviewed, I will help you out.
Once you have a complete backup of your server, you can proceed to the next step.
The newer Linux distribution may have removed or replaced tools that your website or CMS uses. Mostly, popular CMS like WordPress will not have any issue. If you have a custom CMS that might be using a certain library, make sure it still exists in the newer version of the operating system.
Setup temporary server
The entire purpose of this article is to upgrade a live server without any downtime. While the server is upgrading, it may restart multiple times hence the website will not open during the restart. The best way to avoid it from happening is to create a separate server and restore your website on the new server.
You can restore the backup on the new server and point the domain name to the new server temporarily. During the upgrade, visitors will visit the temporary website instead of the main.
We have already covered how to migrate a WordPress website from one server to another in detail.
Set up load balancer
Load balancer is the best way to manage traffic on your website and make sure every visitor accesses the site no matter what’s happening on the server. Load balancer may cost a little but worth using if you receive a large amount of traffic on your website.
During the upgrade, we can use premium load balancer services and redirect all the traffic to our temporary server without changing domain settings.
If you use the Cloudflare firewall, you are in luck. Cloudflare provides load balancing at a cost of $5/month. It’s cheap and you can cancel it anytime.
Enter the IP address of main website server and temporary server in load balancer. After successfully connecting servers with the load balancer, it will redirect the visitors to the website tha’t is functioning properly.
In case your main server does not respond during the update, load balancer will serve visitors temporary website. After the server has been upgraded, we can remove the temporary server.
Start server upgrade when the least traffic is on site
Even though the above points will prevent your services from going down, still it is better to start the upgrade when you receive the least traffic on site. You can use Google Analytics or any other website analytics service you’ve connected with your website.
Once the server has been upgraded, you can point the domain name to the main server and remove the temporary server after a few hours. If you did not change the domain settings and used a load balancer instead, you can delete the temporary server and remove the temporary server’s IP address from the load balancer.
A failed upgrade can cause a real problem for your services. It is extremely important to plan server upgrades and prevent losing any data during the upgrade.