How can I install PHP / PHP on Debian 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 install libapache2-mod-php which allows you to host and serve PHP applications with Apache web server.

Update system

As always, we recommend updating software repositories and installed packages to sync with latest releases.

sudo apt update && sudo apt -y upgrade

Install PHP on Debian

The next step is installation of PHP on Debian OS. Run the following commands on your Debian terminal to install PHP.

sudo apt -y install php php-common

Confirm PHP version.

# Debian 12
$ php -v
PHP 8.2.7 (cli) (built: Jun  9 2023 19:37:27) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.2.7, Copyright (c) Zend Technologies
    with Zend OPcache v8.2.7, Copyright (c), by Zend Technologies

# Debian 11
$ php -v
PHP 7.4.33 (cli) (built: Jun  9 2023 16:51:37) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.33, Copyright (c), by Zend Technologies

# Debian 10
$ php -v
PHP 7.3.31-1~deb10u5 (cli) (built: Sep  4 2023 21:49:25) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.31, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.3.31-1~deb10u5, Copyright (c) 1999-2018, by Zend Technologies

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

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 12
sudo a2enmod php8.* 

# Debian 11/10
sudo a2enmod php7.*

$ sudo systemctl restart apache2

Best book to learn PHP and Web programming:

LEAVE A REPLY

Please enter your comment!
Please enter your name here