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.
In this Article, we will show you how to install PHP 8.0 on Debian 11 system.
Step 1: update packages
Before installing php, make sure system is up to date and install few packages.
sudo apt update
sudo apt install lsb-release ca-certificates apt-transport-https software-properties-common
Also Read -> How to Install Vagrant on Ubuntu 20 04
step 2: Install php 8 using SURI Repo
First we will install Gpg Key before adding repo using following command.
sudo wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg
Now Add suri repository to your system.
sudo sh -c 'echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list'
Then Perform package index update to confirm the repository has been added
sudo apt update
sudo apt install php8.0
sample output:
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
apache2 apache2-data apache2-utils libapache2-mod-php8.0 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 php-pear
The following NEW packages will be installed:
apache2 apache2-data apache2-utils libapache2-mod-php8.0 php-common php8.0 php8.0-cli php8.0-common php8.0-opcache php8.0-readline ssl-cert
0 upgraded, 11 newly installed, 0 to remove and 5 not upgraded.
Need to get 4,752 kB of archives.
After this operation, 21.7 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
once php is isntalled, you can check the php version.
php -v
output:
PHP 8.0.10 (cli) (built: Aug 26 2021 16:06:19) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.10, Copyright (c) Zend Technologies
with Zend OPcache v8.0.10, Copyright (c), by Zend Technologies
Also Read -> How to Install Sonarqube on Ubuntu 20 04
Step 3: Install php Modules
Now you can install required php modules.To install PHP 8 extensions on Debian use following command.
sudo apt install php8.0-<extension>
Note : replace extension with your requirement.
samle output:
you can install few of the php extensions using below command.
sudo apt install php8.0-{gd,pgsql,soap,mysql,cli,common,imap,ldap,xml,fpm,curl,mbstring,zip}
To check loaded PHP modules use the following command.
php -m
That's it. Now you have successfully installed php 8 on debian 11 Bullseye.
Also Read -> How to Install LAMP stack on Debian 11