How to Upgrade PHP on Debian 9 10 11

0
(0)

Upgrade or Install PHP 8.1 on Debian running Apache2

This tutorial shows how to install or upgrade PHP 8.1 quick and easy for Apache web server running on Debian 9 or Debian 10 and Debian 11. PHP is the widely used server scripting language for dynamic and interactive websites and content management systems.

5 steps to perform PHP 8.1 for Apache2 on Debian.

1. Updating Debian as root

$ su -
$ apt update
$ apt upgrade -y && reboot

2. Add SURY PHP PPA Repository

SURY is a third-party repository that offers current PHP versions for Debian GNU/Linux, which is added as root.

$ apt -y install lsb-release apt-transport-https ca-certificates
$ wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg
$ echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" | tee /etc/apt/sources.list.d/php.list

3. Installing PHP 8.1 on Debian

$ apt update
$ apt -y install php8.1
$ update-alternative --set php /usr/bin/php8.1

More than one PHP version can be installed on the system, run update-alternatives --set php [version] to enable a Version.

4. Install Important Modules for PHP 8.1 on Debian

$ apt -y install php8.1-cli php8.1-curl php8.1-gd php8.1-intl php8.1-mbstring php8.1-mysql php8.1-opcache php8.1-readline php8.1-xml php8.1-xsl php8.1-zip php8.1-bz2

5. Making PHP 8.1 module for Apache available

$ apt -y install libapache2-mod-php8.1
$ systemctl reload apache2

Finish! the installation is done. If you want to know which installed PHP version and modules are actually available, the next section shows.

Check the current PHP version

$ php -v
PHP 8.1.1 (cli) (built: Dec 20 2021 21:33:24) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.1, Copyright (c) Zend Technologies
    with Zend OPcache v8.1.1, Copyright (c), by Zend Technologies

Show current PHP configuration

The current PHP settings are displayed by creating a .php-file with the following content, to output the detailed settings in the web browser.

<?php
phpinfo();
?>

Save the file as phpinfo.php in the “/html” directory. Then open the newly created .php-file in a web browser.

http://my-domain/phpinfo.php
view phpinfo in web browser
Image: http://my-domain/phpinfo.php

The system-wide PHP settings can be found under the path /etc/php, for modification using Apache 2 edit the php.ini file.

$ vi /etc/php/8.1/apache2/php.ini

If you do not see the installed php version, may the apache php module need to change to the desired version, run the apache helper command in the terminal, replace the version you have instead, like here php.7.3 in this example.

$ a2dismod php7.4
$ a2enmod php8.1
$ systemctl restart apache2

Verify the running php module with view the phpinfo.php from the web browser.

The PHP modules available for Apache 2 can find in the Apache web server path under /etc/apache2/mods-available.

$ ll /etc/apache2/mods-available/php*
-rw-r--r-- 1 root root 855 Jul  5  2020 /etc/apache2/mods-available/php7.3.conf
-rw-r--r-- 1 root root 102 Jul  5  2020 /etc/apache2/mods-available/php7.3.load
-rw-r--r-- 1 root root 855 Dec 20 22:32 /etc/apache2/mods-available/php7.4.conf
-rw-r--r-- 1 root root 102 Dec 20 22:32 /etc/apache2/mods-available/php7.4.load
-rw-r--r-- 1 root root 855 Dec 20 22:32 /etc/apache2/mods-available/php8.1.conf
-rw-r--r-- 1 root root 101 Dec 20 22:32 /etc/apache2/mods-available/php8.1.load

Disable an Apache 2 module with a2dismod, use a2enmod to enable. The apt info command provides information about module information.

$ apt info libapache2-mod-php8.1

How useful was this post?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate this post.

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?

Leave a Reply

Your email address will not be published.