installphp.info


← Back to home page

Install PHP 7.2 on Debian 11

Warning! This PHP version is end-of-life!

PHP 7.2 reached end of life on 30 Nov 2020 and is no longer being updated. It's strongly recommended to upgrade to the latest version as soon as possible. You can read the official PHP migration guide here.

Installing PHP 7.2 on Debian 11

Prerequisites

  • Root access or sudo privileges on your Debian 11 system
  • Terminal access
  • Internet connection for downloading packages

Installation

  1. Update the package list:

    sudo apt update
  2. Install the required dependencies:

    sudo apt install -y lsb-release ca-certificates apt-transport-https software-properties-common
  3. Add the Sury PHP repository:

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

    wget -qO - https://packages.sury.org/php/apt.gpg | sudo apt-key add -
  5. Update the package list again:

    sudo apt update
  6. Install PHP 7.2 and common extensions:

    sudo apt install -y php7.2 php7.2-cli php7.2-common php7.2-curl php7.2-gd php7.2-json php7.2-mbstring php7.2-mysql php7.2-xml

Verification

  1. Check the PHP version:

    php -v

    The output should display PHP 7.2.x

  2. Verify installed PHP modules:

    php -m

    This will list all installed PHP modules

  3. Create a test PHP file:

    echo '<?php phpinfo(); ?>' | sudo tee /var/www/html/phpinfo.php
  4. Access the PHP info page in your web browser:

    http://your_server_ip/phpinfo.php

    This will display detailed information about your PHP installation