• Categories
    Category
    {{ postCtrl.tags }}
    • {{ category.tag_type }}

      • {{tag.tag_name}}
      • View more
  • Categories
    Category
    {{ postCtrl.tags }}
    • {{ category.tag_type }}

      • {{tag.tag_name}}
      • View more
  • News
  • Tutorials
  • Forums
  • Tags
  • Users
Tutorial News Comments FAQ Related Articles

How to install and enable PHP 8.1 on Debian 11.3

  • 00:32 cat /etc/os-release
  • 00:41 php -v
  • 00:54 sudo apt -y install lsb-release apt-transport-https ca-certificates
  • 01:06 sudo wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg
  • 01:24 echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" | sudo tee /etc/apt/sources.list.d/php.list
  • 01:50 sudo apt install php libapache2-mod-php php8.1-mysql php8.1-common php8.1-mysql php8.1-xml php8.1-xmlrpc php8.1-curl php8.1-gd php8.1-imagick php8.1-cli php8.1-dev php8.1-imap php8.1-mbstring
  • 02:18 sudo sh -c 'echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list'
  • 02:30 wget -qO - https://packages.sury.org/php/apt.gpg | sudo apt-key add –
  • 02:42 apt update
  • 02:50 php -v
  • 03:06 dpkg --get-selections | grep -i php
  • 03:33 sudo update-alternatives --config php
  • 03:50 php -v
{{postValue.id}}

To install and enable PHP 8.1 on Debian 11.3

Introduction

PHP abbreviated as “HyperText Processor”, is the open-source programming language used for Web application development. It is a scripting language, mostly used for the front end with HTML. It can be used to create e-commerce websites, manage databases, and do session monitoring. It is available for all OS. The latest version of PHP is version 8.1 and, in this article, we will discuss the install and Enable PHP 8.1 On Debian 11.3.

Step 1: Check the OS version by using the below command

[root@linuxhelp ~]# cat /etc/os-release
PRETTY_NAME="Debian GNU/Linux 11 (bullseye)"
NAME="Debian GNU/Linux"
VERSION_ID="11"
VERSION="11 (bullseye)"
VERSION_CODENAME=bullseye

Step 2: Check the PHP version by using the below command

[root@linuxhelp ~]#  php -v
PHP 7.4.28 (cli) (built: Feb 17 2022 16:17:19) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.28, Copyright (c), by Zend Technologies

Step 3: Add the SURY PPA for PHP 8.1 by using the below command

[root@linuxhelp ~]#  sudo apt -y install lsb-release apt-transport-https ca-certificates
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
ca-certificates is already the newest version (20210119).
ca-certificates set to manually installed.
lsb-release is already the newest version (11.1.0).
lsb-release set to manually installed.
The following NEW packages will be installed:
  apt-transport-https

[root@linuxhelp ~]#  sudo wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg
--2022-06-10 01:19:32--  https://packages.sury.org/php/apt.gpg
Resolving packages.sury.org (packages.sury.org)... 122.10.251.138

/etc/apt/trusted.gpg.d/p 100%[===============================>]   1.73K  --.-KB/s    in 0s      

2022-06-10 01:19:37 (56.2 MB/s) - ‘/etc/apt/trusted.gpg.d/php.gpg’ saved [1769/1769]

Step 4: Add the PPA to the server packages by using the below command

[root@linuxhelp ~]#  echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" | sudo tee /etc/apt/sources.list.d/php.list
deb https://packages.sury.org/php/ bullseye main

Step 5: Update the packages by using the below command

[root@linuxhelp ~]#  sudo apt update
Get:1 http://security.debian.org/debian-security bullseye-security InRelease [44.1 kB]
Hit:2 http://deb.debian.org/debian bullseye InRelease                                           
Get:3 http://deb.debian.org/debian bullseye-updates InRelease [39.4 kB]
Get:4 http://security.debian.org/debian-security bullseye-security/main Sources [124 kB]
Get:9 https://packages.sury.org/php bullseye InRelease [6,841 B]
128 packages can be upgraded. Run 'apt list --upgradable' to see them.

Step 6: Install the PhP 8.1 packages by using the below command

[root@linuxhelp ~]#  sudo apt install php libapache2-mod-php php8.1-mysql php8.1-common php8.1-mysql php8.1-xml php8.1-xmlrpc php8.1-curl php8.1-gd php8.1-imagick php8.1-cli php8.1-dev php8.1-imap php8.1-mbstring php8.1-opcache php8.1-soap php8.1-zip php8.1-intl -y
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following packages were automatically installed and are no longer required:
  libapache2-mod-php7.4 php7.4
Selecting previously unselected package php8.1-common.
Processing triggers for libapache2-mod-php8.1 (8.1.6-1+0~20220517.17+debian11~1.gbp6b3bd1) ...

Step 7: Enable SURY Repository packages by using the below command

[root@linuxhelp ~]# sudo sh -c 'echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list'

Step 8: Import the GPG key for the repository by the below-mentioned command:

[root@linuxhelp ~]#  wget -qO - https://packages.sury.org/php/apt.gpg | sudo apt-key add –
Warning: apt-key is deprecated. Manage keyring files in trusted.gpg.d instead (see apt-key(8)).
OK

Step 9: Update the packages by using the below command

[root@linuxhelp ~]#   apt update

Hit:1 http://security.debian.org/debian-security bullseye-security InRelease
Reading package lists... Done                       
Building dependency tree... Done
Reading state information... Done
123 packages can be upgraded. Run 'apt list --upgradable' to see them.
apt install mongodb-org
PHP 7.4.28 (cli) (built: Feb 17 2022 16:17:19) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.28, Copyright (c), by Zend Technologies

Step 11: Switch the PHP version by using the below command

[root@linuxhelp ~]#  dpkg --get-selections | grep -i php

libapache2-mod-php				install
libapache2-mod-php7.4			install
libapache2-mod-php8.1			install


[root@linuxhelp ~]#  sudo update-alternatives --config php

There are 3 choices for the alternative php (providing /usr/bin/php).

  Selection    Path                  Priority   Status
------------------------------------------------------------
* 0            /usr/bin/php.default   100       auto mode
  1            /usr/bin/php.default   100       manual mode
  2            /usr/bin/php7.4        74        manual mode
  3            /usr/bin/php8.1        81        manual mode

Press <enter> to keep the current choice[*], or type selection number: 3
update-alternatives: using /usr/bin/php8.1 to provide /usr/bin/php (php) in manual mode

Step 12: Check the PHP version by using the below command

[root@linuxhelp ~]#  php -v


PHP 8.1.6 (cli) (built: May 17 2022 16:48:41) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.6, Copyright (c) Zend Technologies
    with Zend OPcache v8.1.6, Copyright (c), by Zend Technologies

Conclusion:

We have reached the end of this article. In this guide, we have walked you through the steps required to How to Install and Enable PHP 8.1 On Debian 11.3. Your feedback is much welcome.

Tags:
michael
Author: 

Comments ( 0 )

No comments available

Add a comment
{{postCtrl.cmtErrMsg}}

Frequently asked questions ( 5 )

Q

1. What is the command to check PHP Version on Debian 11.3?

A

Php -v is the command to check PHP Version on Debian 11.3.

Q

2. What is the command to Enable the sury Repository?

A

sudo apt -y install lsb-release apt-transport-https ca-certificates
sudo wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg

Q

3. How to install PHP 8.1 Debian 11.3?

A

sudo apt install php libapache2-mod-php php8.1-mysql php8.1-common php8.1-mysql php8.1-xml php8.1-xmlrpc php8.1-curl php8.1-gd php8.1-imagick php8.1-cli php8.1-dev php8.1-imap php8.1-mbstring php8.1-opcache php8.1-soap php8.1-zip php8.1-intl -y

Q

4. What is the command Switch Between Php Versions?

A

sudo update-alternatives --config php

Q

5. How to Update the packages?

A

Sudo apt update

Back To Top!
Rank
User
Points

Top Contributers

userNamenaveelansari
135850

Top Contributers

userNameayanbhatti
92510

Top Contributers

userNamehamzaahmed
32150

Top Contributers

1
userNamelinuxhelp
31040

Top Contributers

userNamemuhammadali
24500
Can you help Luke ?
workbench for debian

I am using workbench in CentOS whereas now I need to use Debian Operating system so could you please help to install and use in Debian?

Networking
  • Routing
  • trunk
  • Netmask
  • Packet Capture
  • domain
  • HTTP Proxy
Server Setup
  • NFS
  • KVM
  • Memory
  • Sendmail
  • WebDAV
  • LXC
Shell Commands
  • Cloud commander
  • Command line archive tools
  • last command
  • Shell
  • terminal
  • Throttle
Desktop Application
  • Linux app
  • Pithos
  • Retrospect
  • Scribe
  • TortoiseHg
  • 4Images
Monitoring Tool
  • Monit
  • Apache Server Monitoring
  • EtherApe 
  • Arpwatch Tool
  • Auditd
  • Barman
Web Application
  • Nutch
  • Amazon VPC
  • FarmWarDeployer
  • Rukovoditel
  • Mirror site
  • Chef
Contact Us | Terms of Use| Privacy Policy| Disclaimer
© 2025 LinuxHelp.com All rights reserved. Linux™ is the registered trademark of Linus Torvalds. This site is not affiliated with linus torvalds in any way.