Skip to content

How to Install PHP (8.5, 8.4 & 7.4) on Debian 13

Debian 13 ships PHP 8.4. Add the Sury repository when you need PHP 8.5 or an older 7.4 or 5.6 for legacy code, and run several versions side by side.

Category
PHP
Covers
Debian
Versions & support
About PHP →, About Debian →
On this page

Debian 13 (Trixie) ships PHP 8.4 in its default repositories, so you can install a current, supported PHP with a single apt command. If you need something else, such as the newer PHP 8.5 or an older release like PHP 7.4 or 5.6 for a legacy application, the Debian PHP repository maintained by Ondřej Surý (packages.sury.org) provides every branch from 5.6 to 8.5, built for Debian 13.

This guide covers both methods. You will install PHP from Debian’s own repository or from the Sury repository, add the extensions most applications need, connect PHP to Apache or Nginx, and run several PHP versions side by side on the same server.

You need a Debian 13 system, a user with sudo privileges, and an internet connection.

Which PHP version should you install?

  • PHP 8.4 is the default on Debian 13. Debian’s security team patches it for the whole life of the release, so it is the safest choice for most servers. Upstream support for 8.4 runs until 31 December 2028.
  • PHP 8.5 is the newest release (November 2025), supported until 31 December 2029. Use it when your application supports it and you want the latest features. It is only available from the Sury repository.
  • PHP 8.3 and older (8.2, 8.1, 8.0, 7.4, 5.6) are also in the Sury repository. Every branch from 8.1 down no longer receives upstream fixes, so only use them to run old code while you migrate it.

You can check the current support status of every PHP branch on our PHP versions and end-of-life dates page.

Method 1: Install PHP 8.4 from the Debian repository

If PHP 8.4 is all you need, you don’t need any extra repository. Update the package index and install PHP:

sudo apt update
sudo apt install php8.4-cli php8.4-fpm -y

This installs the command-line interpreter and PHP-FPM. Installing the plain php or php8.4 package also works, but it pulls in the Apache web server by default, which you may not want on an Nginx server.

Check the installed version:

php -v

PHP 8.4.24 (cli) (built: ...) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.4.24, Copyright (c) Zend Technologies
    with Zend OPcache v8.4.24, Copyright (c), by Zend Technologies

You can now skip to installing extensions.

Method 2: Install PHP 8.5, 7.4 or another version from the Sury repository

Step 1: Add the Sury PHP repository

Install the tools needed to add a third-party repository:

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

Download and install the repository’s signing key package:

curl -sSLo /tmp/debsuryorg-archive-keyring.deb https://packages.sury.org/debsuryorg-archive-keyring.deb
sudo dpkg -i /tmp/debsuryorg-archive-keyring.deb

Add the repository. The lsb_release -sc part inserts your Debian codename, which is trixie on Debian 13:

echo "deb [signed-by=/usr/share/keyrings/debsuryorg-archive-keyring.gpg] https://packages.sury.org/php/ $(lsb_release -sc) main" | sudo tee /etc/apt/sources.list.d/php.list
sudo apt update

Make sure the line says trixie. Older guides used bookworm (Debian 12) here, which leads to dependency errors on Debian 13.

Step 2: Install the PHP version you need

Install PHP 8.5:

sudo apt install php8.5-cli php8.5-fpm -y

For another version, change the version number in the package names. For example, PHP 7.4:

sudo apt install php7.4-cli php7.4-fpm -y

The repository provides PHP 8.5, 8.4, 8.3, 8.2, 8.1, 8.0, 7.4, 7.3, 7.2, 7.1, 7.0 and 5.6 for Debian 13. Once the repository is added, the PHP 8.4 packages also come from Sury instead of Debian, so they follow upstream point releases more closely.

Confirm the version:

php -v

PHP 8.5.12 (cli) (built: ...) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.5.12, Copyright (c) Zend Technologies
    with Zend OPcache v8.5.12, Copyright (c), by Zend Technologies

Install PHP extensions

The base packages are deliberately small. This set covers what WordPress, Laravel, Symfony and most other applications expect. Replace 8.5 with your version:

sudo apt install php8.5-{mysql,curl,gd,mbstring,xml,zip,intl,bcmath,soap,readline} -y

Some notes on extensions:

  • OPcache is built into PHP 8.5, so there is no separate package for it. For PHP 8.4 and older, add php8.4-opcache (or your version) to the list. It is the single biggest speed-up on a production server.
  • Use php8.5-pgsql instead of php8.5-mysql if your application uses PostgreSQL.
  • To find any other extension, search for it: apt search php8.5-

List the loaded modules to check them:

php -m

Use PHP with Apache or Nginx

Option A: Apache with mod_php

The simplest setup for a single-version Apache server is the PHP module:

sudo apt install apache2 libapache2-mod-php8.5 -y
sudo systemctl restart apache2

Option B: Apache with PHP-FPM

PHP-FPM uses less memory under load and lets different sites use different PHP versions. Enable the FastCGI proxy modules and the PHP-FPM configuration:

sudo apt install apache2 -y
sudo a2enmod proxy_fcgi setenvif
sudo a2enconf php8.5-fpm
sudo systemctl restart php8.5-fpm apache2

If libapache2-mod-php is also installed, disable it first with sudo a2dismod php8.5 so Apache doesn’t handle PHP twice.

Option C: Nginx with PHP-FPM

Nginx always runs PHP through PHP-FPM. Install Nginx and make sure the FPM service is running:

sudo apt install nginx -y
sudo systemctl enable --now php8.5-fpm

Then pass PHP requests to the FPM socket in your server block, for example in /etc/nginx/sites-available/default:


location ~ \.php$ {
    include snippets/fastcgi-php.conf;
    fastcgi_pass unix:/run/php/php8.5-fpm.sock;
}

Test the configuration and reload Nginx:

sudo nginx -t
sudo systemctl reload nginx

Test PHP in the browser

Create a small test file in the web root:

echo "<?php phpinfo(); ?>" | sudo tee /var/www/html/info.php

Open http://your-server-ip/info.php in a browser. You should see the PHP information page with the version you installed. The Server API line shows whether Apache uses mod_php (Apache 2.0 Handler) or PHP-FPM (FPM/FastCGI).

The page reveals details about your server, so delete it when you are done:

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

Switch between multiple PHP versions

You can install several versions side by side, for example 8.5 and 7.4. The php command on the command line points to one of them. To choose which one:

sudo update-alternatives --config php

Pick the version number from the list. To set it directly without the menu:

sudo update-alternatives --set php /usr/bin/php8.5

This only changes the command-line default. Web servers choose their version separately:

  • Apache with mod_php: disable one module and enable the other, for example sudo a2dismod php7.4 && sudo a2enmod php8.5, then restart Apache.
  • Apache or Nginx with PHP-FPM: point each site to the socket of the version it needs, such as /run/php/php7.4-fpm.sock or /run/php/php8.5-fpm.sock.

Where PHP configuration files live

Each version and each server API has its own php.ini file:

  • Command line: /etc/php/8.5/cli/php.ini
  • PHP-FPM: /etc/php/8.5/fpm/php.ini (pools in /etc/php/8.5/fpm/pool.d/)
  • Apache mod_php: /etc/php/8.5/apache2/php.ini

After editing a file, restart the matching service, for example sudo systemctl restart php8.5-fpm or sudo systemctl restart apache2.

Uninstall a PHP version

To remove a version you no longer need, purge its packages:

sudo apt purge 'php7.4*' -y
sudo apt autoremove -y

Conclusion

Debian 13 gives you PHP 8.4 out of the box, and that is the right choice for most servers. Add the Sury repository when you need PHP 8.5 or an older version for an application you haven’t migrated yet, and use PHP-FPM if you want to run several versions on one server. PHP releases a new version every November, so check the PHP release history from time to time and plan upgrades before your version reaches end of life.

Rahul

Rahul Kumar is the founder and chief editor of TecAdmin.net. A Red Hat Certified Engineer (RHCE), he has worked in IT since 2009, with hands-on experience in Linux system administration, DevOps, web hosting, cloud platforms and automation. He started TecAdmin in 2013 to share practical, step-by-step guides, and leads its editorial work with one aim: making technical learning clear and useful for sysadmins, developers and beginners alike.

Leave a Reply

Your email address will not be published. Required fields are marked *


Back to top