14
August
2026
How to upgrade PHP from version 8.1 to 8.4
14:58

How to upgrade PHP from version 8.1 to 8.4

14 August 2026 14:58

In 2026, there are two ways to update PHP.

Introduction

Во Many versions of Linux still use PHP 8.1. Modern projects may require a newer version of 8.3 or 8.4 to run. The latest version available for installation is PHP 8.5.

First way- installing PHP 8.3, 8.4 or 8.5 from the oandrej PPA repository

sudo add-apt-repository ppa:ondrej/apache2
sudo LC_ALL=C.UTF-8 add-apt-repository ppa:ondrej/php

Second way- installing PHP from a third-party deb repository https://packages.sury.org/php/
In the article I looked at the second method - deb from packages.sury.org/php/.

How to install new versions of PHP

First of all, I recommend disabling the previous repository and removing the outdated PHP7.

sudo add-apt-repository --remove ppa:ondrej/php
sudo apt remove php7*

Message:

This repository is in the process of being merged into https://packages.sury.org/php/

If you read on the website https://packages.sury.org/php file README.txt, the installation path is as follows:

1) prepare for installation: update the package cache and install the utilities that are needed to download the repository key file from the Internet.

sudo apt-get update
sudo apt-get -y install lsb-release ca-certificates curl

2) from the debsuryorg-archive-keyring.deb package downloaded from https://packages.sury.org/
install the repository signing key on your local PC.

First, download the package installation DEB file to the tmp folder:

curl -sSLo /tmp/debsuryorg-archive-keyring.deb \
https://packages.sury.org/debsuryorg-archive-keyring.deb

Then install the package with the key

sudo dpkg -i /tmp/debsuryorg-archive-keyring.deb

The key will appear in the /usr/share/keyrings/ folder,
where is the name of the keychain file:debsuryorg-archive-keyring.gpg

3) In the /etc/apt/sources.list.d/ folder, create an entry for the new repository

The php.list file has one line content:

deb [signed-by=/usr/share/keyrings/debsuryorg-archive-keyring.gpg] https://packages.sury.org/php/ jammy main

Where instead of jammy you need to indicate the code name of your distribution.
The distribution name can be found with the command

lsb_release -a

You can also find out the codename by the Linux version number.
The most popular versions of Linux have code words:

  • Ubuntu 20.04 LTS -focal
  • Ubuntu 22.04 LTS -jammy
  • Ubuntu 24.04 LTS -noble
  • Linux Mint 21 -jammy
  • Linux Mint 22 -noble
  • Debian 11 -bullseye
  • Debian 12 -bookworm
  • Debian 13 -trixie

4) Installing php 8.4

sudo apt-get update
sudo apt-get install php8.4-common

5) Checking the PHP version

php --version

Output: PHP 8.4.24

The PHP version has been updated successfully.

Problems and solutions

In Linux Mint 21, there was an issue updating php8.4-gd due to a dependency on libgd3, which requires a version >= 2.3.3, but the installation candidate in the repository is 2.3.0.

Solution: The Linux operating system repository priority may be higher than that of a third-party repository, preventing programs and libraries from being installed from the third-party repository.

Creating a file to indicate installation priority, i.e. pinning packages to a repository: APT Pinning

sudo nano /etc/apt/preferences

File Contents:

Package: libgd3
Pin: release o=deb.sury.org
Pin-Priority: 1001

Package: php*
Pin: release o=deb.sury.org
Pin-Priority: 1001

1001 - means the highest priority, which is higher than that of the OS system repository.

Previously, the LibGD3 library from the Ubuntu system repository conflicted with the PHP graphics module requirement php8.4-gd use LibGD3 version 2.3.3,

  • in the system repository version 2.3.0,
  • version 2.3.3 from the deb.sury.org repository will be installed as having a higher priority of 1001.

The command says this:

apt-cache policy libgd3

Now there will be no error. We do it as usual:

sudo apt-get update
sudo apt-get install php8.4-common

Checking PHP version

php --version

Switching PHP version in OS by default

Only if the PHP version is not the one required:

sudo update-alternatives --config php

Installing the Apache HTTP Server Module

sudo apt-get install libapache2-mod-php8.4

Causes of the error "undefined constant IMG_JPG"

When running a PHP project that uses graphics, you may receive an error regarding IMG_JPG

If you have completed the previous steps (installing php one of the latest 8.x versions), you need to additionally install the module:

sudo apt-get install libgd3
sudo apt-get install php8.4-gd

List of Apache2 modules to install

For the project, I additionally installed the Apache web server packages and modules:

sudo apt install php8.4 php8.4-cli php8.4-common
sudo apt install libapache2-mod-php8.4 
sudo apt install php8.4-curl php8.4-intl php8.4-mbstring php8.4-mysql
sudo apt install php8.4-readline php8.4-xml php8.4-yaml php8.4-zip php8.4-apcu

Enabling the PHP module

sudo a2enmod php8.4
sudo service apache2 restart

Switching FastCGI FPM / regular module configuration

The status of the module can be found with the command

sudo systemctl status php8.4-fpm

If the FPM module doesn't exist or the FPM version is the same as PHP (i.e. 8.4), do nothing.

If the PHP and FPM versions are different, disable the FCGI and FPM modules:

sudo a2dismod actions alias proxy_fcgi
sudo a2disconf php8.4-fpm

And enable them:

sudo a2enconf php8.4-fpm
sudo a2enmod actions alias proxy_fcgi

This article has been tested with PHP version 8.4, but may work with versions 8.3 and 8.5 if you replace the corresponding numbers in the terminal commands.



Related publications