‍PHP is a widely-used server-side programming language that powers dynamic websites. With its powerful features, including a Just-in-time (JIT) compiler, attributes, and named arguments, PHP is the foundation for popular platforms like WordPress, Magento, Drupal, and Joomla. In this tutorial, we will guide you through the process of installing PHP 8.0 on Debian 11.

Prerequisites

Before we begin, make sure you have the following:

  • A server running Debian 11.
  • A configured root password.

Update Your System

To ensure that you have the latest packages, it is essential to update your system. Run the following command:

apt-get update -y

Add PHP Repository

By default, PHP 8.0 is not included in the Debian 11 default repository. Therefore, we need to add the Sury PHP repository to APT.

First, install the required packages:

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

Once the packages are installed, add the Sury repository to APT:

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:

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

Update the repository:

apt-get update -y

Install PHP 8.0

Now, let’s install PHP 8.0 using the following command:

apt-get install php8.0

To verify the installation, run:

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

Depending on your application requirements, you may need to install additional PHP extensions. Use the following command to install popular extensions:

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

Configure PHP 8 for Apache

To configure PHP 8 for Apache, you need to edit the php.ini file and modify certain values.

Open the php.ini file with the following command:

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

Make the following changes:

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 Apache to apply the changes:

systemctl restart apache2

Upgrade to PHP 8

If you have multiple PHP versions installed on your server, you may need to disable the default PHP version and enable PHP 8.0.

To disable a specific PHP version, use the a2dismod command. For example, to disable PHP 7.4, run:

a2dismod php7.4

To enable PHP 8.0, use the a2enmod command:

a2enmod php8.0

Finally, restart the Apache service:

systemctl restart apache2

Verify PHP Installation

To verify that PHP is installed and running correctly, create an info.php file in the Apache web root directory:

nano /var/www/html/info.php

Add the following line to the file:

<?php phpinfo(); ?>

Save and close the file. Then, access the info.php file in your web browser using the URL http://your-server-ip/info.php. You should see the PHP info page.

Conclusion

Congratulations! You have successfully installed PHP 8.0 on Debian 11. You can now update your existing PHP version and take advantage of the latest features and improvements. If you have any questions or need further assistance, feel free to reach out to us.

Remember, for reliable and scalable cloud hosting solutions, Shape.host is here to help. Explore our Cloud VPS services and experience the power of secure and efficient hosting.