How to Install PHP 8 on Debian 11 Bullseye

PHP is one of the most popular and widely used server-side programming languages to date on the market. According to PHP website statistics, in 2021, it will be used by 79.1% of all known websites according to W3Tech, with version 7.0 series making up the bulk with 65.6% market share. Many popular CMS and frameworks such as WordPress, Magento, and Laravel development involve most PHP frameworks.

The latest PHP release to date is the 8 series. PHP 8 is a significant update of the PHP language. It contains many new features and optimizations, including named arguments, union types, attributes, constructor property promotion, match expression, null safe operator, JIT, improvements in the type system, error handling, and consistency.

In the following tutorial, you will learn how to install the latest repository by the Debian maintainer Ondřej Surý and install PHP 8.0 and install future versions such as the incoming PHP 8.1.


  • Recommended OS: Debian 11 Bullseye
  • User account: A user account with sudo or root access.
  • Required Packages: wget

Updating Operating System

First, before anything, update your Debian operating system to make sure all existing packages are up to date:

sudo apt update && sudo apt full-upgrade -y

Root or Sudo Access

By default, when you create your account at startup with Debian compared to other distributions, it does not automatically receive sudoers status. You must either have access to the root password to use the su command or visit our tutorial on How to Add a User to Sudoers on Debian.

Install Required Dependencies

You will need to have the following packages installed for this tutorial. Execute the following command to install:

sudo apt-get install ca-certificates apt-transport-https software-properties-common -y

Note, if unsure, run the command regardless; it will not harm your system.

Installing PHP 8 for Debian 11

Import & Install GPG key:

The first step is to import and install the GPG key before adding the repository. To do this, use the following terminal (CTRL+ALT+T) command:

sudo wget -O /etc/apt/trusted.gpg.d/php.gpg

Note, you may need to install these dependencies if you have trouble:

sudo apt install apt-transport-https lsb-release ca-certificates

Import & Install Repository:

With the GPG key sorted, it is time to add the Ondřej Surý repository as follows:

sudo sh -c 'echo "deb $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list'

Install PHP 8

Now you can proceed to install PHP 8 for your particular need as follows:

Install Apache Module Option

To install PHP 8 as an Apache module, enter the following command.

sudo apt update && sudo apt install php8.0 libapache2-mod-php8.0

Once installation is complete, restart your Apache server for the new PHP module to be loaded.

sudo systemctl restart apache2

Install Apache Module Option with FPM

PHP-FPM (an acronym of FastCGI Process Manager) is a hugely popular alternative PHP (Hypertext Processor) FastCGI implementation.

To install PHP-FPM for Apache 2, use the following commands.

sudo apt update && sudo apt install php8.0-fpm libapache2-mod-fcgid

Note, by default, PHP-FPM is not enabled for Apache. You must enable it by the following command.

sudo a2enmod proxy_fcgi setenvif && sudo a2enconf php8.0-fpm

Lastly, restart Apache.

sudo systemctl restart apache2

Verify that PHP-FPM is working:

sudo systemctl status php8.0-fpm

Example output:

How to Install PHP 8 on Debian 11 Bullseye

PHP 8 with Nginx Option

Nginx does not contain native PHP processing like some other web servers like Apache. You will need to install PHP-FPM “fastCGI process manager” to handle the PHP files.

To install PHP 8 on Nginx, use the following command:

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

Now, confirm it is running:

sudo systemctl status php8.0-fpm

Example output:

How to Install PHP 8 on Debian 11 Bullseye

Comments and Conclusion

PHP 8 is an improvement over 7.4, with speed an exciting factor amongst most features. However, you must be aware that it’s still not considered “mature software” compared to PHP 7.4. You may find that many of your favorite software like WordPress or Plugins/Themes for CMS software may conflict.

Do some research, prepare, and have 7.4 installed and ready to replace if anything goes wrong when making the switch, as 7.4 is still actively developed and packages pushed simultaneously along with the 8 packages.


Like to get automatic updates? Follow us on one of our social media accounts!