How to Install PHP 8.4 in Debian 12 Bookworm / 11 Bullseye

This tutorial shows how to install or upgrade to PHP 8.4 for your web server in Debian 12 Bookworm or Debian 11 Bullseye.

PHP announced new 8.4 release few weeks ago with performance improvements and new features, such as property hooks, asymmetric visibility, lazy objects, an object API for BCMath, new array functions, and new JIT implementation based on IR Framework.

Here’s a step by step guide shows how to install or upgrade to the new php 8.4 for your Apache 2 or Nginx web server in Debian through Ondřej Surý’s apt repository.

About the package maintainer

Ondřej Surý is the Debian developer since 2000. He has been packaging php package for Debian since php 5.

Besides making official php packages in Debian and Ubuntu, he also maintains Ubuntu PPA and Debian DPA that contain alternative php packages. They are so far php 5.6, php 7.0 – 7.4, and php 8.0 – 8.4.

Add the Debian DPA and install PHP 8.4

The Debian DPA so far supports Debian 11/12 on amd64, arm64, armhf, and i386 CPU platforms.

1. Get the gpg key

First, connect to your Debian server or open terminal from start menu if you’re running on the desktop edition.

Then download the key by running command:

sudo wget https://packages.sury.org/php/apt.gpg -O /etc/apt/keyrings/deb.sury.org.gpg

This command will use the wget to download the gpg file from the DPA, then save as deb.sury.org.gpg file under /etc/apt/keyrings directory.

Just in case, you may first need to:

  • install wget via sudo apt install wget command.
  • create the keyrings directory via sudo mkdir -p /etc/apt/keyrings command.

To make sure if the key is properly installed, try ls /etc/apt/keyrings to list the directory content and see if the key is there.

2. Add the Debian DPA

Next, create a source file by running command in terminal:

sudo nano /etc/apt/sources.list.d/deb.sury.org.list

This command will create the deb.sury.org.list file for a new apt source, then open it via nano command line text editor.

When file opens, add the line below to tell the source URL and point to the signed key.

deb [signed-by=/etc/apt/keyrings/deb.sury.org.gpg] https://packages.sury.org/php bookworm main

NOTE: You need to replace bookworm (Debian 12) with bullseye if you’re working on Debian 11. If you don’t even know your system edition, run cat /etc/os-release to tell.

To save the file, press Ctrl+S and then Ctrl+X to exit.

3. Install PHP 8.4

Finally, refresh the package cache by running command:

sudo apt update

In the output, it should include something look like: “Get: x https://packages.sury.org/php xxx”

After that, install:

  • either php 8.4, apache 2 module, and mysql etc modules accordingly:
    sudo apt install php8.4 libapache2-mod-php8.4 php8.4-mysql
  • or install php-fpm plus other modules for Nginx:
    sudo apt install php8.4 php8.4-fpm php8.4-mysql

NOTE: If you have an old php version installed, then you may run the command below to check which modules you previously installed, then install the corresponding ones for php 8.4

apt list --installed |grep php

Apply PHP 8.4 for Apache 2 or Nginx

If this is the first php package you installed on Debian, Apache 2 web server should make use of it automatically.

If NOT, then first disable the old php, for example php8.2, by running command:

sudo a2dismod php8.2

Then, use the command below to enable php8.4 for Apache 2:

sudo a2enmod php8.4

Finally, restart the service to apply change:

sudo systemctl restart apache2

For Nginx, you may first edit the /etc/php/8.4/fpm/pool.d/www.conf according to the old configuration.

Then, edit your site configuration file (replace default accordingly) via command:

sudo nano /etc/nginx/sites-available/default

Find out the location ~ .php$ {} section, and set fastcgi_pass unix:/run/php/php8.4-fpm.sock; Or, leave the file unchanged if you configure php-fpm to listen on TCP port (e.g., 127.0.0.1:9000).

Finally, restart nginx and php-fpm services:

sudo systemctl restart nginx php8.4-fpm

Verify your php details

Finally, run command to create a simple php file under your domain’s root directory:

sudo nano /var/www/html/info.php

Replace /var/www/html if your domain root is not that directory.

Then, add the 3 lines below and press Ctrl+S to save.

<?php
phpinfo ();
?>

Finally, press Ctrl+X to exit the text editor. And, visit either localhost/info.php (from server itself) or your_domain/info.php to check php version and details.

Exit mobile version