Table of contents

Subscribe to our newsletter.
No spam
100% Great content
Unsubscribe anytime

How to keep the LEMP stack up to date

When it comes to keeping your LEMP stack up to date, you will have to manually update each component individually. In this tutorial we are going to cover in detail how to upgrade your Linux, Nginx, MySQL and PHP version.

How to update your Linux system

Start by opening a terminal window. You will then need to update the package repositories using the following command:

sudo apt-get update

The last command will fetch the available package updates to your system. After fetching, you will be able to continue with downloading and installing them as shown in the following command.

sudo apt-get upgrade

This will bring up a list of all the packages that are going to be updated. Make sure you go over them in detail, enter Y to proceed and the update process will then start. Once it has concluded, you might be asked to restart your system in order for the updates to be applied, if that is the case you can then proceed with restarting the system.

IMPORTANT: Before updating, it is always a good idea to backup your system!

One limitation of “apt-get upgrade” is that it never installs new packages and never deletes existing ones, it only upgrades the current packages to their newer versions. If you wish to upgrade to the latest stable version of your Linux distribution, which could include the automatic removal or addition of recommended packages you can do so with this command:

sudo apt-get dist-upgrade

Additionally, if you are using a rolling release distro like Arch, you can update Linux with this command instead:

sudo pacman -Syu

How to update Nginx

It is crucial for your server’s and LEMP stack’s security to keep Nginx up to date. Here’s how to update Nginx for the different Linux versions. Keep in mind that these steps are not needed if you have already run the above steps for upgrading the whole system.

Start by backing up all of your Nginx configuration files:

sudo cp -rf /etc/nginx/nginx.conf /etc/nginx/nginx.conf.bak
sudo cp -rf /etc/nginx/sites-enabled/* /etc/nginx/sites-available/*.bak

Next, you will need to update the package repositories and proceed with proceed to upgrade Nginx.

Debian/Ubuntu:

sudo apt-get update
sudo apt-get upgrade nginx

On CentOS/RHEL only a single command is needed:

sudo yum update nginx

When the update concludes, you will need to verify the Nginx version:

nginx -v

IMPORTANT: If you have made any custom changes to your Nginx configuration files, make sure to carefully review them prior to upgrading in order to ensure that they are still compatible with the version you are going to be installing. The same applies for any additional third-party Nginx modules.

How to keep MySQL up to date

Ubuntu/Debian

Back up your existing MySQL data:

sudo mysqldump -u root -p --all-databases > /path/to/backup.sql

Update the package lists:

sudo apt update

Upgrade MySQL:

sudo apt upgrade mysql-server

Verify the new MySQL version:

mysql --version

CentOS/RHEL

Back up your existing MySQL data:

sudo mysqldump -u root -p --all-databases > /path/to/backup.sql

Upgrade MySQL:

sudo yum update mysql-server

IMPORTANT: If you have altered your configuration files, make sure to check them before upgrading. The same goes for any third-party plugins.

How to update your PHP version

Start by checking your current PHP version:

php -v

Next, update the package list.

Ubuntu/Debian:

sudo apt-get update
sudo apt-get install php8.3 (choose your new version)

CentOS/RHEL:

sudo yum install php8.3 (choose your new version)

Then, check whether the version has been installed:

php -v

To ensure everything will run smoothly, you can finally restart Nginx:

sudo systemctl restart nginx

IMPORTANT: Make sure to check the compatibility with any third-party plugins, extension and PHP frameworks as well as any custom configurations.

Deploy a cloud server with the LEMP stack today!

Configure
Payment methods we accept:
Bitcoin
Lightning Network (Bitcoin)
Litecoin
Credit card
Bank transfer