How to keep the LEMP stack up to date
Published: 03 January 2024 • Updated: 14 August 2026 • 3 min read
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 updateThe 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 upgradeThis 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-upgradeAdditionally, if you are using a rolling release distro like Arch, you can update Linux with this command instead:
sudo pacman -SyuHow 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/*.bakNext, 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 nginxOn CentOS/RHEL only a single command is needed:
sudo yum update nginxWhen the update concludes, you will need to verify the Nginx version:
nginx -vIMPORTANT: 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.sqlUpdate the package lists:
sudo apt updateUpgrade MySQL:
sudo apt upgrade mysql-serverVerify the new MySQL version:
mysql --versionCentOS/RHEL
Back up your existing MySQL data:
sudo mysqldump -u root -p --all-databases > /path/to/backup.sqlUpgrade MySQL:
sudo yum update mysql-serverIMPORTANT: 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 -vNext, 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 -vTo ensure everything will run smoothly, you can finally restart Nginx:
sudo systemctl restart nginxIMPORTANT: Make sure to check the compatibility with any third-party plugins, extension and PHP frameworks as well as any custom configurations.