Intro
This guide covers upgrading from an existing PHP 8.x release to the latest PHP 8.x (including PHP 8.4) on various Linux distributions.
If you need to upgrade from PHP 7.x to PHP 8, please see our separate guide: How to Upgrade from PHP 7.x to PHP 8 on Linux
If you’re on Ubuntu 22.04 or above, you can often install the latest PHP 8.x from the official repositories. If you’re on Ubuntu 20.04 or older, you’ll need Ondřej Surý’s PPA to access the newest PHP 8.x packages.
Other Linux Distros: For Debian or Linux Mint, the commands are nearly identical. For Fedora, CentOS, or RHEL, you would typically use dnf
or yum
, potentially enabling the Remi repository. On Arch Linux, you’d use pacman
. The workflow is the same: remove old PHP packages, then install the new ones.
Prerequisites
Before making any changes to your server, it’s crucial to have a reliable backup. If you’re on a cloud hosting service, create a snapshot of your instance so you can roll back if anything goes wrong.
Check your currently installed version of PHP by running the command below:
php -v
The output might look like this:
Output:
PHP 8.2.10 (cli) (built: Sep 2 2025 20:14:35) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.2.10, Copyright (c) Zend Technologies
with Zend OPcache v8.2.10, Copyright (c), by Zend Technologies
This example shows PHP 8.2.10 installed. Let’s proceed to upgrade to a newer 8.x version, such as PHP 8.4.
1. Identify Your PHP Extensions
When upgrading from one PHP 8.x release to another (for example, 8.2 to 8.4), you also need to upgrade your PHP extensions (e.g., php8.2-curl
to php8.4-curl
). First, list all currently installed PHP 8 packages:
dpkg -l | grep php | tee php8-packages.txt
This command saves the list of installed PHP packages into php8-packages.txt
. Keep it safe in case you need to match your extensions later.
2. Uninstall the Old PHP 8.x Version
We will remove any existing PHP 8.x versions (like PHP 8.1 or 8.2) before installing the newer release. This helps avoid conflicts between packages:
sudo apt-get purge php8.*
Confirm removal by pressing y
and ENTER
when prompted.
If you have phpMyAdmin
installed, you may be prompted about removing its database. Choose NO if you want to keep the existing database intact.
3. Autoclean & Autoremove
After uninstalling PHP 8.x, clear out any redundant packages to keep your system tidy.
sudo apt-get autoclean
sudo apt-get autoremove
Press y
and ENTER
to confirm if prompted.
4. (Optional) Add Ondřej Surý’s PPA Repository
If you are on Ubuntu 22.04 or newer, you typically do not need to add this repository because newer PHP packages should be available in the default Ubuntu repositories.
If you are on Ubuntu 20.04 or older, newer PHP 8.x packages are only available via the Ondřej Surý PPA. Add it below:
sudo add-apt-repository ppa:ondrej/php
Press ENTER
when prompted to continue.
5. Install the Newer PHP 8.x Version
Next, update your package list and install the newer PHP 8.x version. Below is an example for PHP 8.4. (If a newer version is available, replace 8.4
with that version.)
sudo apt-get update
sudo apt-get install php8.4
Press y
and ENTER
if prompted to confirm installation.
If you are running Apache, restart it to activate the new PHP version:
sudo systemctl restart apache2
6. Install PHP 8.x Extensions
Install the matching extensions for your new PHP version. Below is an example for PHP 8.4 with commonly used extensions for WordPress:
sudo apt-get install php8.4-common php8.4-mysql php8.4-xml php8.4-xmlrpc php8.4-curl php8.4-gd php8.4-imagick php8.4-cli php8.4-dev php8.4-imap php8.4-mbstring php8.4-opcache php8.4-soap php8.4-zip php8.4-intl -y
If you are running Nginx, install the PHP-FPM package (matching your new PHP version):
sudo apt-get install php8.4-fpm -y
Restart Apache or Nginx after installing any extensions:
sudo systemctl restart apache2
or if using Nginx:
sudo systemctl restart nginx
sudo systemctl restart php8.4-fpm
7. Verify the Upgrade
Finally, confirm that the new PHP version is active:
php -v
Output:
PHP 8.4.3 (cli) (built: Nov 25 2024 18:09:54) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.4.3, Copyright (c) Zend Technologies
with Zend OPcache v8.4.3, Copyright (c), by Zend Technologies
You have successfully upgraded to PHP 8.4! Remember to test your web applications thoroughly after the upgrade to ensure everything is functioning properly.
Let me know if this helped. Follow me on Twitter, Facebook and YouTube, or 🍊 buy me a smoothie.