Learn how to – How To Install PHP on Debian 11 / Debian 10.
How can I install PHP / PHP on Debian 11 / Debian 10 Linux?. This guide will walk you through the steps to install PHP programming language on Debian Linux system. For Apache web server users, you’ll need to libapache2-mod-php
Debian 10 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 installed packages to sync with latest releases.
sudo apt update && sudo apt -y upgrade
Step 2: Install PHP on Debian
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
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
Best book to learn PHP and Web programming:
- Best Books to learn Web Development – PHP, HTML, CSS, JavaScript and jQuery
- Best Books To Master Web Design
Leave a Reply
You must be logged in to post a comment.