In this short guide we will show you how to install PHP 8.0 on Debian Linux system. PHP a powerful scripting language for web development. Any PHP script can be executed on a Linux, Windows, macOS and Unix system with PHP runtime installed. As of this article writing PHP 8 is available for installation on Debian Linux machine.
In our previous guide we discussed installation of PHP 8 on the following:
The official release of PHP 8 is November 26, 2020. This major release of PHP comes with lots of new features and performance improvements.
You should also expect new breaking changes which means some modifications in your code may be needed to get it running on PHP 8. Some of the nice set of new features coming with PHP 8 are the JIT compiler, named arguments, union types, attributes, and many more.
1) Update System
Before you start installation of PHP 8 on Debian update your system to the latest release.
sudo apt update && sudo apt -y upgrade
Since there could be kernel updates consider system reboot after the upgrade.
[ -e /var/run/reboot-required ] && sudo reboot
2) Add Surý APT repository
PHP 8 packages for Debian are available on the DEB.SURY.ORG repository. Install required dependencies.
sudo apt update
sudo apt install -y lsb-release ca-certificates apt-transport-https software-properties-common gnupg2
Add the PHP packages APT repository to your Debian server.
echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" | sudo tee /etc/apt/sources.list.d/sury-php.list
Import repository key:
curl -fsSL https://packages.sury.org/php/apt.gpg|sudo gpg --dearmor -o /etc/apt/trusted.gpg.d/sury.gpg
Perform package index update to confirm the repository has been added:
$ sudo apt update
Hit:1 http://mirror.hetzner.de/debian/packages buster InRelease
Hit:2 http://security.debian.org buster/updates InRelease
Hit:3 http://mirror.hetzner.de/debian/packages buster-updates InRelease
Hit:4 http://mirror.hetzner.de/debian/packages buster-backports InRelease
Hit:5 http://mirror.hetzner.de/debian/security buster/updates InRelease
Hit:6 http://deb.debian.org/debian buster InRelease
Hit:7 http://deb.debian.org/debian buster-updates InRelease
Hit:8 http://deb.debian.org/debian buster-backports InRelease
Get:9 https://packages.sury.org/php buster InRelease [6,759 B]
Get:10 https://packages.sury.org/php buster/main amd64 Packages [148 kB]
Fetched 155 kB in 2s (83.2 kB/s)
Reading package lists... Done
Building dependency tree
Reading state information... Done
7 packages can be upgraded. Run 'apt list --upgradable' to see them.
3) Install PHP 8 on Debian
With the repository added you can begin the installation of PHP 8.0 on Debian Linux OS.
sudo apt update && sudo apt install php8.0
Hit the y key to start installation:
....
Reading state information... Done
The following additional packages will be installed:
apache2-bin libapache2-mod-php8.0 libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap libbrotli1 libgdbm-compat4 libjansson4 liblua5.2-0 libperl5.28
libsodium23 perl php-common php8.0-cli php8.0-common php8.0-opcache php8.0-readline psmisc
Suggested packages:
apache2-doc apache2-suexec-pristine | apache2-suexec-custom www-browser php-pear perl-doc libterm-readline-gnu-perl | libterm-readline-perl-perl make
libb-debug-perl liblocale-codes-perl
Recommended packages:
apache2
The following NEW packages will be installed:
apache2-bin libapache2-mod-php8.0 libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap libbrotli1 libgdbm-compat4 libjansson4 liblua5.2-0 libperl5.28
libsodium23 perl php-common php8.0 php8.0-cli php8.0-common php8.0-opcache php8.0-readline psmisc
0 upgraded, 20 newly installed, 0 to remove and 7 not upgraded.
Need to get 10.4 MB of archives.
After this operation, 55.1 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Confirm the default PHP version on the server:
$ php -v
PHP 8.0.30 (cli) (built: Jun 6 2024 16:31:41) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.30, Copyright (c) Zend Technologies
with Zend OPcache v8.0.30, Copyright (c), by Zend Technologies
4) Install PHP 8 Extensions
To install PHP 8 extensions on Debian use the following command syntax:
sudo apt install php8.0-<extension>
Where:
- <extension> is replaced with the actual extension name.
Some available extensions are as shown below:
$ sudo apt install php8.0-
php8.0-bcmath php8.0-curl-dbgsym php8.0-gmp-dbgsym php8.0-mysql php8.0-pspell-dbgsym php8.0-tidy
php8.0-bcmath-dbgsym php8.0-dba php8.0-imap php8.0-mysql-dbgsym php8.0-readline php8.0-tidy-dbgsym
php8.0-bz2 php8.0-dba-dbgsym php8.0-imap-dbgsym php8.0-odbc php8.0-readline-dbgsym php8.0-xdebug
php8.0-bz2-dbgsym php8.0-dev php8.0-interbase php8.0-odbc-dbgsym php8.0-snmp php8.0-xml
php8.0-cgi php8.0-enchant php8.0-interbase-dbgsym php8.0-opcache php8.0-snmp-dbgsym php8.0-xml-dbgsym
php8.0-cgi-dbgsym php8.0-enchant-dbgsym php8.0-intl php8.0-opcache-dbgsym php8.0-soap php8.0-xsl
php8.0-cli php8.0-fpm php8.0-intl-dbgsym php8.0-pgsql php8.0-soap-dbgsym php8.0-zip
php8.0-cli-dbgsym php8.0-fpm-dbgsym php8.0-ldap php8.0-pgsql-dbgsym php8.0-sqlite3 php8.0-zip-dbgsym
php8.0-common php8.0-gd php8.0-ldap-dbgsym php8.0-phpdbg php8.0-sqlite3-dbgsym
php8.0-common-dbgsym php8.0-gd-dbgsym php8.0-mbstring php8.0-phpdbg-dbgsym php8.0-sybase
php8.0-curl php8.0-gmp php8.0-mbstring-dbgsym php8.0-pspell php8.0-sybase-dbgsym
Example:
sudo apt install php8.0-{mysql,cli,common,imap,ldap,xml,fpm,curl,mbstring,zip}
Accept installation prompt with the y key.
The following additional packages will be installed:
libc-client2007e libonig5 libxslt1.1 libzip4 mlock
Suggested packages:
uw-mailutils php-pear
The following NEW packages will be installed:
libc-client2007e libonig5 libxslt1.1 libzip4 mlock php8.0-curl php8.0-fpm php8.0-imap php8.0-ldap php8.0-mbstring php8.0-mysql php8.0-xml php8.0-zip
0 upgraded, 13 newly installed, 0 to remove and 7 not upgraded.
Need to get 3,308 kB of archives.
After this operation, 10.3 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Use the same installation format for all other PHP extensions available in the repository. To check loaded PHP modules use the command:
php -m
Recommended books to read:
- PHP, HTML, CSS, JavaScript and jQuery
- Web Design Books
- CSS & CSS3 Learning Books
- Best Books To Learn HTML & HTML5
- Best Apache and Nginx reference Books
it helped me a lot. thanks
Thanks and welcome
Thanks! I got helped.
I got massage “apt-key is deprecated. Manage keyring files in trusted.gpg.d instead” in step2.
So I also referred “https://packages.sury.org/php/README.txt”.
Doesn’t seem to work in Debian 9 (Stretch):
$ sudo apt update
Ign:1 http://ftp.de.debian.org/debian stretch InRelease
Hit:2 http://ftp.de.debian.org/debian-security stretch/updates InRelease
Ign:3 https://packages.sury.org/php stretch InRelease
Hit:4 http://ftp.de.debian.org/debian stretch-updates InRelease
Err:5 https://packages.sury.org/php stretch Release
403 Forbidden
Hit:6 http://ftp.de.debian.org/debian stretch-backports InRelease
Hit:7 http://ftp.de.debian.org/debian stretch Release
Reading package lists… Done
E: The repository ‘https://packages.sury.org/php stretch Release’ does not have a Release file.
N: Updating from such a repository can’t be done securely, and is therefore disabled by default.
N: See apt-secure(8) manpage for repository creation and user configuration details.
Excellent! Thank you very much
Welcome and thanks for visiting our website
Not working:
Err:13 https://packages.sury.org/php focal Release
404 Not Found [IP: 84.17.46.54 443]
Thanks for your help with my php installation solution
Great happy to learn it was helpful.