How can I install PHP / PHP 7.3 on Debian 10 / Debian 11 Linux?. This guide will walk you through the steps to install PHP 7.3 / PHP 7.4 on Debian 10/11. For Apache web server users, you’ll need to install libapache2-mod-php
which allows you to host and serve PHP applications with Apache web server.
Debian 10 Buster has PHP 7.3 as the default version installable, while Debian 11 comes with PHP 7.4. The only pre-requisite for this setup is pre-installed Debian and user account with sudo access.
Step 1: Update system
As always, we recommend updating software repositories and installe packages to sync with latest releases.
sudo apt update && sudo apt -y upgrade
Step 2: Install PHP on Debian 10 (Buster) / Debian 11 (Bullseye)
The next step is installation of PHP 7.x on Debian 10 / Debian 11. Run the following commands on your Debian terminal to install PHP.
sudo apt -y install php php-common
Confirm PHP version.
# Debian 11
$ php -v
PHP 7.4.25 (cli) (built: Oct 23 2021 21:53:50) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
with Zend OPcache v7.4.25, Copyright (c), by Zend Technologies
# Debian 10
$ php -v
PHP 7.3.29-1~deb10u1 (cli) (built: Jul 2 2021 04:04:33) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.29, Copyright (c) 1998-2018 Zend Technologies
with Zend OPcache v7.3.29-1~deb10u1, Copyright (c) 1999-2018, by Zend Technologies
Step 3: Installing PHP Extensions on Debian 10 / Debian 11
PHP extensions can be installed on demand. Here I’ll show installation of most common PHP extensions required for basic usage.
sudo apt -y install php-cli php-fpm php-json php-pdo php-mysql php-zip php-gd php-mbstring php-curl php-xml php-pear php-bcmath
Step 4: Using PHP with Apache Web Server
You need to have installed Apache Web Server, see below:
Then install libapache2-mod-php
sudo apt -y install libapache2-mod-php
Enable Apache module if not already enabled then restart the Web Server.
# Debian 10
$ sudo a2enmod php7.*
Considering dependency mpm_prefork for php7.3:
Considering conflict mpm_event for mpm_prefork:
Considering conflict mpm_worker for mpm_prefork:
Module mpm_prefork already enabled
Considering conflict php5 for php7.3:
Module php7.3 already enabled
# Debian 11
$ sudo a2enmod php7.*
Considering dependency mpm_prefork for php7.4:
Considering conflict mpm_event for mpm_prefork:
Considering conflict mpm_worker for mpm_prefork:
Module mpm_prefork already enabled
Considering conflict php5 for php7.4:
Module php7.4 already enabled
$ sudo systemctl restart apache2