How to Install PHP 8 on Debian 11

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.


  • 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 $(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 - | 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:

<?php phpinfo(); ?>

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:

PHP 8 on Debian 11


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.

Share this page:

4 Comment(s)