PHP is a free, Open-source, and popular server-side programming language used for creating dynamic websites. PHP comes with many powerful features includes a Just-in-time (JIT) compiler, attributes, named arguments, and more. Many popular platforms including, WordPress, Magento, Drupal, and Joomla are based on PHP.

In this tutorial, I will show you how to install PHP 8.0 on Debian 11.

Prerequisites

  • A server running Debian 11.
  • A root password is configured on the server.

Update Your System

Before starting, it is a good idea to update your system to the latest packages. You can update all of them using the following command:

apt-get update -y

Once all the packages are updated, you can proceed to the next step.

Add PHP Repository

By default, PHP 8.0 is not included in the Debian 11 default repository. So you will need to add the Sury PHP repository to APT.

First, install the required packages using the following command:

apt-get install ca-certificates apt-transport-https software-properties-common -y

Once all the packages are installed, add a Sury repository to APT using the following command:

echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" | tee /etc/apt/sources.list.d/sury-php.list

Next, download and add the GPG key with the following command:

wget -qO - https://packages.sury.org/php/apt.gpg | apt-key add -

Once you are done, update the repository with the following command:

apt-get update -y

Install PHP 8.0

Now, install the PHP 8.0 using the following command:

apt-get install php8.0

Once the PHP is installed, verify the installed version of PHP using the following command:

php -v

You should see the following output:

PHP 8.0.10 (cli) (built: Aug 26 2021 16:06:19) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.10, Copyright (c) Zend Technologies
    with Zend OPcache v8.0.10, Copyright (c), by Zend Technologies

Install PHP 8 Extensions

You can install different PHP extensions based on your application requirements using the following command:

apt-get install php php-common php-xml php-gd php-mbstring php-tokenizer php-json php-bcmath php-zip -y

Once all the PHP extensions are installed, you can proceed to the next step.

Configure PHP 8 for Apache

You will need to edit the php.ini file and change some value for web applications.

You can edit it with the following command:

nano /etc/php/8.0/apache2/php.ini

Change the following lines:

upload_max_filesize = 32M 
post_max_size = 48M 
memory_limit = 256M 
max_execution_time = 600 
max_input_vars = 3000 
max_input_time = 1000

Save and close the file then restart the Apache to apply the changes.

systemctl restart apache2

Upgrade to PHP 8

If there are multiple PHP versions installed in your server. You will need to disable the default PHP version and enable the PHP 8 version.

For example, run the following command to disable the PHP 7.4 version:

a2dismod php7.4

Next, enable the PHP 8.0 version using the following command:

a2enmod php8.0

Next, restart the Apache service to apply the changes:

systemctl restart apache2

Verify PHP

Next, you will need to create an info.php file inside the Apache web root directory to test the PHP version:

You can create it with the following command:

nano /var/www/html/info.php

Add the following line:


Once you are finished, open your web browser and access the info.php file using the URL http://your-server-ip/info.php. You should see the PHP page on the following screen:

<img alt="PHP 8 on Debian 11" data-ezsrc="https://kirelos.com/wp-content/uploads/2021/09/echo/p1.png61386b8b5af39.jpg" ezimgfmt="rs rscb5 src ng ngcb5" height="451" loading="lazy" src="data:image/svg xml,” width=”750″>

Conclusion

In the above guide, you learned how to install PHP 8.0 on Debian 11. I hope you can now easily update your existing PHP version. Feel free to ask me if you have any questions.

<img alt="Hitesh Jethva" data-ezsrc="https://kirelos.com/wp-content/uploads/2021/09/echo/hitesh-80.jpg" ezimgfmt="rs rscb5 src ng ngcb5" src="data:image/svg xml,”>

About Hitesh Jethva

Over 8 years of experience as a Linux system administrator. My skills include a depth knowledge of Redhat/Centos, Ubuntu Nginx and Apache, Mysql, Subversion, Linux, Ubuntu, web hosting, web server, Squid proxy, NFS, FTP, DNS, Samba, LDAP, OpenVPN, Haproxy, Amazon web services, WHMCS, OpenStack Cloud, Postfix Mail Server, Security etc.