×
UpdatePHP Pro Log in Register
PHP expiry alert : PHP v8.1 has recently expired. Is your website still running this version? Click here for more details
SAFE versions of PHP: 8.5.12, 8.4.27, 8.3.36, 8.2.35
☰

PHP2Shell (CVE-2026-109618 / CVE-2026-109619) is a critical security problem in PHP itself that lets attackers take over web servers. Every website that runs PHP should be updated to 8.5.12, 8.4.27, 8.3.36, 8.2.35 or newer as soon as possible. Read our PHP2Shell check and patch guide.

Disclaimer: before attempting to update the PHP version of your website we would highly recommend that you make a full backup of it, just in case anything goes wrong.

This guide covers Ubuntu and the distributions built on top of it, which include Linux Mint, elementary OS, Zorin OS and Pop!_OS. They all use the same apt package manager and the same package names, so the commands below work on each of them. The examples use PHP 8.4, so replace 8.4 with whichever supported branch you want to install.

Check which PHP version you have now

Open a terminal, or connect to your server over SSH, and run the command below to see the PHP version used on the command line. Bear in mind that your web server can be set up to use a different version, so it is also worth checking your site with our free PHP version checker.

php -v

It also helps to make a note of the PHP extensions you have installed, because you will want the same ones for the new version. This command lists every installed PHP package:

dpkg -l | grep php | awk '{print $2}'

Option 1: use the version that ships with your release

Each Ubuntu release comes with one PHP branch in its own repositories, and Ubuntu keeps it patched with security fixes for the life of that release. If that branch is still supported by the PHP project, the simplest and safest route is to keep your system up to date:

sudo apt update sudo apt upgrade

Linux Mint, elementary OS and Zorin OS follow the Ubuntu LTS release they are based on, so they offer the same PHP branch as that release. If the branch is older than you need, move on to option 2.

Option 2: install a newer branch from the ondrej/php PPA

The ondrej/php PPA is maintained by Ondřej Surý, who also packages PHP for Debian. It is the most widely used source of current PHP packages for Ubuntu, and it lets several PHP versions sit side by side on the same machine. Add it with the following commands:

sudo apt update sudo apt install software-properties-common sudo add-apt-repository ppa:ondrej/php sudo apt update

Now install the new PHP version together with the extensions your site needs. The list below covers what most content management systems such as WordPress, Joomla and Drupal expect, but you should compare it with the list of packages you noted down earlier and add anything that is missing.

sudo apt install php8.4 php8.4-cli php8.4-fpm php8.4-common php8.4-mysql php8.4-xml php8.4-mbstring php8.4-curl php8.4-zip php8.4-gd php8.4-intl php8.4-bcmath

On Linux Mint, the add-apt-repository command automatically uses the Ubuntu release that your version of Mint is based on, so there is nothing extra to do. The PPA only builds packages for Ubuntu releases that are still supported, so if your release has reached its end of life you will need to upgrade the operating system first.

Switch Apache over to the new version

If Apache runs PHP through the mod_php module, disable the module for the old version and enable the one for the new version, then restart Apache. Replace 8.1 with the version you are moving away from.

sudo apt install libapache2-mod-php8.4 sudo a2dismod php8.1 sudo a2enmod php8.4 sudo systemctl restart apache2

If Apache uses PHP-FPM instead, which is the faster and more common setup today, switch the configuration that Apache loads and then restart both services:

sudo a2enmod proxy_fcgi setenvif sudo a2disconf php8.1-fpm sudo a2enconf php8.4-fpm sudo systemctl restart php8.4-fpm apache2

Switch Nginx over to the new version

Nginx always talks to PHP through PHP-FPM. Open your site's configuration file, which is usually found in /etc/nginx/sites-available/, and change the fastcgi_pass line so that it points at the socket for the new version:

fastcgi_pass unix:/run/php/php8.4-fpm.sock;

Test the configuration and reload Nginx so that the change takes effect:

sudo nginx -t sudo systemctl reload nginx

Change the default command line version

When more than one PHP version is installed, Ubuntu uses the alternatives system to decide which one runs when you type php. Tools such as Composer, WP-CLI and cron jobs use this version, so it is worth setting it to match your website:

sudo update-alternatives --set php /usr/bin/php8.4 php -v

Copy your settings and remove the old version

Each PHP version has its own configuration in /etc/php/8.4/, so any changes you made to php.ini for the old version, such as the memory limit or the maximum upload size, need to be made again in the new one. Once your site has been tested and works correctly, you can remove the old version to keep the server tidy:

sudo apt purge 'php8.1*' sudo apt autoremove

Are you still stuck?

If your site shows errors after the upgrade, our guide to common PHP errors after upgrading explains the usual causes. It may also be time to call in a professional to assist, so check out our listings of PHP developers that can help upgrade or maintain your website.

Back to Updating PHP manually on Linux systems
Article last updated: 24th October, 2026