Debian 12 - Install PHP 8.4
The easiest way to install later versions of PHP such as PHP 8.4 is to add Ondrej's repository.
sudo apt update \
&& sudo apt install ca-certificates apt-transport-https -y \
&& sudo wget -O /usr/share/keyrings/deb.sury.org-php.gpg https://packages.sury.org/php/apt.gpg \
&& sudo sh -c 'echo "deb [signed-by=/usr/share/keyrings/deb.sury.org-php.gpg] https://packages.sury.org/php/ $(lsb_release -sc) main" \
> /etc/apt/sources.list.d/php.list'
Then you just need to install the PHP version you want. E.g.
sudo apt update \
&& sudo apt install php8.4-cli -y
Removing Existing PHP
If you had already installed PHP from native packages remove it before installing the later version:
sudo apt-get remove php8.2 php8.2-* -y
sudo apt autoremove -y
Last updated: 10th March 2025
First published: 30th June 2023
First published: 30th June 2023