Friday, December 27, 2024
Google search engine
HomeGuest BlogsHow To Install PHP 8.1 on Debian 11/10/9

How To Install PHP 8.1 on Debian 11/10/9

.tdi_3.td-a-rec{text-align:center}.tdi_3 .td-element-style{z-index:-1}.tdi_3.td-a-rec-img{text-align:left}.tdi_3.td-a-rec-img img{margin:0 auto 0 0}@media(max-width:767px){.tdi_3.td-a-rec-img{text-align:center}}

How can I install PHP 8.1 on Debian 11/Debian 10/Debian 9 Linux system?. PHP 8.1 is the latest version of PHP as of this article update, released on November 25, 2021. PHP is a powerful scripting language for web applications development and creation of dynamic web pages. A PHP script is executable on any Windows, Linux, BSD, and macOS system provided PHP runtime is installed. The PHP language was originally created by Danish-Canadian programmer Rasmus Lerdorf, in 1994. It nows enjoys contribution from thousands of developers, companies and open source enthusiasts.

New features in PHP 8.1 Programming Language

  • Readonly properties – Class properties can be marked as readonly hence can only be written once
  • Support for DNS-over-HTTPS (DoH)
  • AVIF Image Format support – The PHP 8.1’s image processing and GD extension adds support for AVIF images.
  • Never Return Type – A new return type hint called never is added in PHP 8.1
  • Added support for Fibers – The low level mechanism to manage parallelism
  • File Uploads with CURLStringFile – In PHP 8.1, PHP Curl extension now supports HTTP(S) requests with file uploads
  • Enums – They are now added in PHP 8.1
  • Addition of pure intersection types feature
  • PHP 8.1 adds array_is_list as a built-in function
  • Explicit Octal Numeral Notation
  • New fdatasync() and fsync() Functions
  • Define final Class Constants
  • Intersection Types
  • You can check complete list of PHP 8.1 new features, improvements, and deprecations

For Rocky Linux 8 / AlmaLinux 8 and CentOS 8, use the following guide to install PHP 8.1;

If migrating from PHP 7.x, you should expect new breaking changes which means some modifications in your code may be needed to get it running on PHP 8.1. Review your application requirements thoroughly before performing a major PHP upgrade in your system.

.tdi_2.td-a-rec{text-align:center}.tdi_2 .td-element-style{z-index:-1}.tdi_2.td-a-rec-img{text-align:left}.tdi_2.td-a-rec-img img{margin:0 auto 0 0}@media(max-width:767px){.tdi_2.td-a-rec-img{text-align:center}}

Step 1: Update Debian System

We recommend you perform any installation on an upgraded Debian system. Run the commands provided to upgrade all packages and minor release of your Debian system.

sudo apt update
sudo apt -y upgrade

OS release can be checked with the command below:

$ cat /etc/os-release
PRETTY_NAME="Debian GNU/Linux 11 (bullseye)"
NAME="Debian GNU/Linux"
VERSION_ID="11"
VERSION="11 (bullseye)"
VERSION_CODENAME=bullseye
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"

If your kernel was upgraded you can reboot the system to start using it.

sudo reboot

Step 2: Add Surý APT repository to Debian

TheDEB.SURY.ORG repository is a home for packaging various software into Debian and Ubuntu based Linux distributions. It contains the latest binary builds of PHP 8.1. The repository has to be added manually on the system.

Install required temporary packages:

sudo apt update
sudo apt install -y lsb-release ca-certificates apt-transport-https software-properties-common gnupg2

Add Surý Debian PPA repository to your Debian system.

echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" | sudo tee /etc/apt/sources.list.d/sury-php.list

Import packages signing GPG key;

curl -fsSL  https://packages.sury.org/php/apt.gpg| sudo gpg --dearmor -o /etc/apt/trusted.gpg.d/sury-keyring.gpg

Confirm if the repository is working by downloading package information from all configured sources:

$ sudo apt update
Hit:1 http://security.debian.org/debian-security bullseye-security InRelease
Hit:2 http://deb.debian.org/debian bullseye InRelease
Hit:3 http://deb.debian.org/debian bullseye-updates InRelease
Hit:4 http://deb.debian.org/debian bullseye-backports InRelease
Hit:5 https://packages.sury.org/php bullseye InRelease
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
All packages are up to date.

Step 3: Install PHP 8.1 on Debian 11/10/9

Once you’ve added the repository and is confirmed to be functional, we can proceed with the installation of PHP 8.1 o Debian 11/10/9 Linux system.

sudo apt update 
sudo apt install php8.1

All dependency packages are installed automatically for you. Just hit y in your keyboard to proceed:

....
Reading state information... Done
The following additional packages will be installed:
  apache2 apache2-bin apache2-data apache2-utils bzip2 libapache2-mod-php8.1 libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap libgdbm-compat4 libjansson4 liblua5.3-0 libperl5.32
  libsodium23 mailcap mime-support perl perl-modules-5.32 php-common php8.1-cli php8.1-common php8.1-opcache php8.1-readline ssl-cert
Suggested packages:
  apache2-doc apache2-suexec-pristine | apache2-suexec-custom www-browser bzip2-doc php-pear perl-doc libterm-readline-gnu-perl | libterm-readline-perl-perl make libtap-harness-archive-perl
The following NEW packages will be installed:
  apache2 apache2-bin apache2-data apache2-utils bzip2 libapache2-mod-php8.1 libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap libgdbm-compat4 libjansson4 liblua5.3-0 libperl5.32
  libsodium23 mailcap mime-support perl perl-modules-5.32 php-common php8.1 php8.1-cli php8.1-common php8.1-opcache php8.1-readline ssl-cert
0 upgraded, 26 newly installed, 0 to remove and 0 not upgraded.
Need to get 14.3 MB of archives.
After this operation, 77.2 MB of additional disk space will be used.
Do you want to continue? [Y/n] y

Installed version of PHP can be checked with the command below after a successful installation

$ php -v
PHP 8.1.9 (cli) (built: Aug 15 2022 09:47:52) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.9, Copyright (c) Zend Technologies
    with Zend OPcache v8.1.9, Copyright (c), by Zend Technologies

Step 4: Install PHP 8.1 Extensions on Debian 11/10/9

PHP 8.1 modules can be installed as packages using below command syntax:

sudo apt install php8.1-<extension>

Where:

  • <extension> is replaced with the actual extension name.

Below is an example to install MySQL PHP extension:

$ sudo apt install php8.1-mysql
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following NEW packages will be installed:
  php8.1-mysql
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 116 kB of archives.
After this operation, 466 kB of additional disk space will be used.
Get:1 https://packages.sury.org/php bullseye/main amd64 php8.1-mysql amd64 8.1.0~rc6-3+0~20211120.8+debian11~1.gbp2227b0 [116 kB]
Fetched 116 kB in 0s (1152 kB/s)
Selecting previously unselected package php8.1-mysql.
(Reading database ... 37704 files and directories currently installed.)
Preparing to unpack .../php8.1-mysql_8.1.9-1+0~20220815.24+debian11~1.gbp4d5b5a_amd64.deb ...
Unpacking php8.1-mysql (8.1.9-1+0~20220815.24+debian11~1.gbp4d5b5a) ...
Setting up php8.1-mysql (8.1.9-1+0~20220815.24+debian11~1.gbp4d5b5a) ...

Creating config file /etc/php/8.1/mods-available/mysqlnd.ini with new version

Creating config file /etc/php/8.1/mods-available/mysqli.ini with new version

Creating config file /etc/php/8.1/mods-available/pdo_mysql.ini with new version
Processing triggers for libapache2-mod-php8.1 (8.1.9-1+0~20220815.24+debian11~1.gbp4d5b5a) ...
Processing triggers for php8.1-cli (8.1.9-1+0~20220815.24+debian11~1.gbp4d5b5a) ...

To install all commonly used PHP extensions run the following commands a user with sudo privileges:

sudo apt install php8.1-{bcmath,fpm,xml,mysql,zip,intl,ldap,gd,cli,bz2,curl,mbstring,pgsql,opcache,soap,cgi}

Continue with the installation:

....
uggested packages:
  libgd-tools php-pear
The following NEW packages will be installed:
  fontconfig-config fonts-dejavu-core libdeflate0 libfontconfig1 libgd3 libjbig0 libjpeg62-turbo libonig5 libpq5 libtiff5 libwebp6 libx11-6 libx11-data libxau6 libxcb1 libxdmcp6 libxpm4 libxslt1.1
  libzip4 php8.1-bcmath php8.1-bz2 php8.1-cgi php8.1-curl php8.1-gd php8.1-intl php8.1-ldap php8.1-mbstring php8.1-pgsql php8.1-soap php8.1-xml php8.1-zip
0 upgraded, 31 newly installed, 0 to remove and 0 not upgraded.
Need to get 7150 kB of archives.
After this operation, 26.5 MB of additional disk space will be used.
Do you want to continue? [Y/n] y

Check loaded PHP modules using the command;

$ php --modules
[PHP Modules]
bcmath
bz2
calendar
Core
ctype
curl
date
dom
exif
FFI
fileinfo
filter
ftp
gd
gettext
hash
iconv
intl
json
ldap
libxml
mbstring
mysqli
mysqlnd
openssl
pcntl
pcre
PDO
pdo_mysql
pdo_pgsql
pgsql
Phar
posix
readline
Reflection
session
shmop
SimpleXML
soap
sockets
sodium
SPL
standard
sysvmsg
sysvsem
sysvshm
tokenizer
xml
xmlreader
xmlwriter
xsl
Zend OPcache
zip
zlib

[Zend Modules]
Zend OPcache

That’s all we had to cover on how to install PHP 8.1 on Debian 11 / Debian 10 / Debian 9 Linux system. PHP is a general-purpose scripting language that enables you to develop dynamic and interactive websites with ease. If you’re just getting started with Web programming, give PHP a try and you could fall for it.

PHP Web Programming Video Courses:

.tdi_4.td-a-rec{text-align:center}.tdi_4 .td-element-style{z-index:-1}.tdi_4.td-a-rec-img{text-align:left}.tdi_4.td-a-rec-img img{margin:0 auto 0 0}@media(max-width:767px){.tdi_4.td-a-rec-img{text-align:center}}

RELATED ARTICLES

Most Popular

Recent Comments