How to Install PHP 8.0 on Debian 11 Bullseye


PHP is a programming language used to develop server-side applications. It is one of the most popular languages to date, with code that can be embedded into HTML pages. PHP code is executed on the server, producing HTML or other types of output, which is then sent to the client’s web browser. PHP can be used for many tasks, such as developing dynamic web pages, generating images, and even sending and receiving cookies. In addition, PHP can connect to databases and access files on the server. As a result, PHP is an essential tool for developing modern web applications.

PHP 8.0 is a significant update of the PHP language, released on December 3, 2020. This new version includes many features that improve performance and enable greater flexibility in coding. For example, PHP 8.0 introduces union types, allowing a single variable to hold multiple data types. This can be handy when working with complex data structures. Other new features include Named Arguments, which make it easier to call functions with multiple arguments, and the Printf Directive, which allows printf-style string formatting within PHP code. In addition, this release has updated or improved many existing features. Overall, PHP 8.0 is a welcome addition that will help make PHP an even more powerful and flexible language.

In the following tutorial, you will learn how to install or upgrade PHP 8.0 on Debian 11 Bullseye using the command line terminal using the PHP repository by Ondřej Surý, a renowned Debian maintainer.

Update Debian

First, update your system to ensure all existing packages are up to date.

sudo apt update && sudo apt upgrade -y

Install Dependencies

The first step is to install the dependencies needed for the installation.

Advertisement


To do this, use the following command in your terminal:

sudo apt install dirmngr ca-certificates software-properties-common gnupg gnupg2 apt-transport-https curl -y

Import Ondřej Surý PHP Repository

To begin with, import the PHP repository by Ondrej, who has been a PHP maintainer for Debian for over a decade. This safe repository contains a much more updated version of 8.0 than Debian’s default APT repository.

See also  How to Install AnyDesk on Debian 11/10

Import the PPA using the following command.

curl -sSL https://packages.sury.org/php/README.txt | sudo bash -x

Once done, it is good to refresh your APT repositories, as the PPA may bring additional upgrades to existing dependencies.

sudo apt update

After importing the PPA and running an update, you should see a few packages that need updating; run an upgrade now.

sudo apt upgrade

Install PHP 8.0 with Apache Option

If you run an Apache HTTP server, you can run PHP as an Apache module or PHP-FPM.

Advertisement


Install Apache Module

To install PHP 8.0 as an Apache module, enter the following command.

sudo apt install php8.0 php8.0-common libapache2-mod-php8.0 php8.0-cli

Once installation is complete, restart your Apache server to load the new PHP module.

sudo systemctl restart apache2

Install Apache with PHP-FPM

PHP-FPM (an acronym of FastCGI Process Manager) is a hugely popular alternative PHP (Hypertext Processor) FastCGI implementation.

To install PHP-FPM with the following commands.

sudo apt install php8.0-fpm php8.0-common libapache2-mod-fcgid php8.0-cli

Note, that by default, PHP-FPM is not enabled for Apache. You must enable it by the following command.

sudo a2enmod proxy_fcgi setenvif && sudo a2enconf php8.0-fpm

Lastly, restart Apache.

Advertisement


sudo systemctl restart apache2

Verify that PHP-FPM is working:

systemctl status php8.0-fpm

If everything is ok, proceed to enable FPM in your web service.

As a reminder, to see what version of PHP 8.0 is installed on your system, use the following command.

php --version

Example output:

PHP 8.0.22 (cli) (built: Aug 15 2022 09:50:12) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.22, Copyright (c) Zend Technologies
    with Zend OPcache v8.0.22, Copyright (c), by Zend Technologies

Install PHP 8.0 with Nginx Option

Nginx does not contain native PHP processing like other web servers like Apache. To handle the PHP files, you must install PHP-FPM “fastCGI process manager.”

First, check for updates on your system and install PHP-FPM, natively installing the PHP packages required.

Advertisement


In your terminal, use the following command to install PHP 8.0 and PHP 8.0-FPM.

sudo apt install php8.0 php8.0-fpm php8.0-cli -y

Once installed, the PHP-FPM service is automatically started, and you can check the status to make sure it’s running ok.

sudo systemctl status php8.0--fpm

If everything is okay, proceed to enable FPM in your web service.

See also  How to Install ImageMagick on Rocky Linux 9

You will need to edit your Nginx server block and add the example below for Nginx to process the PHP files.

Below is an example of all server blocks that process PHP files that need the location ~ .php$ added.

server {
 location ~ .php$ {
   include snippets/fastcgi-php.conf;
   fastcgi_pass unix:/run/php/php8.0-fpm.sock;
 }

Test Nginx to make sure you have no errors with the adjustments made with the code above; enter the following.

Advertisement


sudo nginx -t

Example output:

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

Restart the Nginx service for installation to be complete.

sudo systemctl restart nginx

As a reminder, to see what version of PHP 8.0 is installed on your system, use the following command.

php --version

Example output:

PHP 8.0.22 (cli) (built: Aug 15 2022 09:50:12) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.22, Copyright (c) Zend Technologies
    with Zend OPcache v8.0.22, Copyright (c), by Zend Technologies

Optional Extra PHP 8.0 Extensions

While most would opt to install PHP themselves and know what packages to install, below are examples of commands that can be combined or modified.

First, you can pick which modules you require from the following command to install extensions that will automatically enable them with your PHP installation.

Advertisement


sudo apt install php8.0-cli php8.0-curl php8.0-mysqlnd php8.0-gd php8.0-opcache php8.0-zip php8.0-intl php8.0-common php8.0-bcmath php8.0-imap php8.0-imagick php8.0-xmlrpc php8.0-readline php8.0-memcached php8.0-redis php8.0-mbstring php8.0-apcu php8.0-xml php8.0-dom php8.0-redis php8.0-memcached php8.0-memcache

Remove the options you do not want. This is optional. It is highly recommended to only install and keep what modules you require from a performance and security standard.

You can use the following command to view modules loaded at any time.

php -m

Example output:

How to Install PHP 8.0 on Debian 11 Bullseye

Depending on how many modules you have installed, this can be pretty large, and it is always recommended to keep an eye on this and remove any you do not need.

See also  How to Install Linux Kernel 6.0 on Debian 11/10

Lastly, use the following command for anyone interested in installing the development branch.

sudo apt install php8.0-dev

Additional developments tool, such as debugging tools, use the following command.

Advertisement


sudo apt install php8.0-xdebug php8.0-pcov

This will install many dependencies, and unless you are developing with PHP or have some special requirement to install it, do not use this version.

Comments and Conclusion

PHP 8.0 is becoming the new standard as more developers update their code to be compatible with it and take advantage of its advantages from the previous 7.4 version, while most are already implementing support for 8.1, which is now considered stable given 8.2 is in RC status which both promises even more speed improvements and security enhancements over 8.0. So if you want to make your website faster and more secure, switch to PHP 8.0 now.


Not what you were looking for? Try searching for additional tutorials.

2 thoughts on “How to Install PHP 8.0 on Debian 11 Bullseye”

  1. У вас лишее тире тут:
    sudo systemctl status php8.0–fpm
    А за статью огромное спасибо! Главное актуально, свежие версии.

    Reply
    • Спасибо, что указали на это, иногда трудно заметить эти маленькие ошибки при написании команд под мой размер экрана.

      Я ценю это сообщение.

      Reply

Leave a Comment