In this tutorial, you will learn how to install PHP 8 on Debian 11. PHP 8.0 is a major update of the PHP language.
It contains many new features and optimizations including named arguments, union types, attributes, constructor property promotion, match expression, nullsafe operator, JIT, and improvements in the type system, error handling, and consistency.
Install PHP 8 on Debian 11
The default Debian 11 repositories provide PHP 7.4;
apt-cache policy php
php:
Installed: (none)
Candidate: 2:7.4+76
Version table:
2:7.4+76 500
500 http://deb.debian.org/debian bullseye/main amd64 Packages
Install SURY APT Repository
To install PHP 8 on Debian 11, you need to install SURY, third party repositories that provides PHP packages as follows;
apt -y install apt-transport-https lsb-release ca-certificates curl wget
wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg
sh -c 'echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list'
Run System Update
Re-synchronize your system packages to the latest versions;
apt update
Install PHP 8 on Debian 11
PHP 8 is now available for installation;
apt-cache policy php
php:
Installed: (none)
Candidate: 2:8.0+84+0~20210621.36+debian11~1.gbp28513e
Version table:
2:8.0+84+0~20210621.36+debian11~1.gbp28513e 500
500 https://packages.sury.org/php bullseye/main amd64 Packages
2:7.4+76 500
500 http://deb.debian.org/debian bullseye/main amd64 Packages
You can now install PHP 8 on Debian 11 by running the command below;
apt install php8.0
This command will install PHP 8 along with other required package dependencies.
Reading package lists... Done Building dependency tree... Done Reading state information... Done The following additional packages will be installed: apache2 apache2-bin apache2-data apache2-utils libapache2-mod-php8.0 libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap liblua5.3-0 libsodium23 php-common php8.0-cli php8.0-common php8.0-opcache php8.0-readline ssl-cert Suggested packages: apache2-doc apache2-suexec-pristine | apache2-suexec-custom www-browser php-pear The following NEW packages will be installed: apache2 apache2-bin apache2-data apache2-utils libapache2-mod-php8.0 libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap liblua5.3-0 libsodium23 php-common php8.0 php8.0-cli php8.0-common php8.0-opcache php8.0-readline ssl-cert 0 upgraded, 18 newly installed, 0 to remove and 3 not upgraded. Need to get 6,658 kB of archives. After this operation, 28.5 MB of additional disk space will be used. Do you want to continue? [Y/n] y
Confirming the installed version;
php -v
PHP 8.0.9 (cli) (built: Jul 30 2021 13:09:45) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.9, Copyright (c) Zend Technologies
with Zend OPcache v8.0.9, Copyright (c), by Zend Technologies
Installing other PHP 8 modules;
You can install other PHP 8 modules using the command;
apt install php8.0-EXTENSION
Replace EXTENSION with the specific module/extension. For example;
apt install php8.0-mysql php8.0-xml
And that is it.
That is all on how to install PHP 8 on Debian 11.
Other Tutorials
Install MariaDB 10.6 on Debian 11