How to Install PHP 8 on Debian

Cloudbooklet
4 min readNov 28, 2020
Install PHP 8 on Debian

How to Install PHP 8 on Debian. This guide let you learn how install the latest PHP version 8 on your Debian system or your Debian server on any VPS or any Cloud or any Dedicated hosting and configure it with Apache and Nginx.

The latest PHP 8 version is officially released on November 26th, 2020. It comes with a number of new features and a few incompatibilities that you should be aware of before upgrading from the previous version.

This installation is tested on Google Cloud Platform with a Compute Compute Engine VM Instance. So this set up is guaranteed to work on all Linux based servers.

Click here for 2 Months FREE Managed WordPress Hosting in Kinsta

Prerequisites

  1. A Debian server set up with sudo privileges.

Getting Started

Make sure your Debian server is having the latest packages by running the following command.

sudo apt update
sudo apt upgrade

This will update the package index and update the installed packages to the latest version.

Download SURY PPA for PHP 8

Download the Sury PPA for PHP 8 package using wget.

sudo apt -y install lsb-release apt-transport-https ca-certificates wget
sudo wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg

Once you have downloaded the PPA you can add it to the server packages.

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

Now you can proceed the installation of PHP 8 by updating the system.

sudo apt update

Install PHP 8 for Apache

Execute the following command to install PHP 8

sudo apt install php8.0

After the installation has completed, you can confirm the installation using the following command

php -v

Install PHP 8 FPM for Nginx

For Nginx you need to install FPM, execute the following command to install PHP 8 FPM.

sudo apt install php8.0-fpm

After the installation has completed, confirm that PHP 8 FPM has installed correctly with this command.

php-fpm8.0 -v

Install PHP 8 Extensions

Installing PHP extensions are simple with the following syntax.

sudo apt install php8.0-extension_name

Now, install some commonly used php-extensions with the following command.

sudo apt install php8.0-{common,mysql,xml,xmlrpc,curl,gd,imagick,cli,dev,imap,mbstring,opcache,soap,zip,intl,bcmath} -y

Configure PHP 8.0

Now we configure PHP for Web Applications by changing some values in php.ini file.

For PHP 8 with Apache the php.ini location will be in following directory.

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

For PHP 8.0 FPM with Nginx the php.ini location will be in following directory.

sudo nano /etc/php/8.0/fpm/php.ini

Hit F6 for search inside the editor and update the following values for better performance.

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

Once you have modified your PHP settings you need to restart your Apache for the changes to take effect.

Configure PHP 8 FPM Pools

PHP 7.4 FPM allows you to configure the user and group that the service will run under. You can modify these with these commands

sudo nano /etc/php/8.0/fpm/pool.d/www.conf

Change the following lines by replacing the www-data with your username.

user = username 
group = username
listen.owner = username
listen.group = username

Hit CTRL+X and Y to save the configuration and check if the configuration is correct and restart PHP.

Restart PHP 8 FPM

Once you have updated your PHP FPM settings you need to restart it to apply the changes.

sudo php-fpm8.0 -t 
sudo service php8.0-fpm restart

Now you are having PHP 8.0 Installed and configured.

Upgrade to PHP 8 for Apache

Once you have installed PHP 8 you need to upgrade to the latest installed version of PHP.

You need to disable the old PHP version and enable the new PHP version 8.

sudo a2dismod php7.4

This command will disable the PHP 7.4 module.

sudo a2enmod php8.0

This command will enable the PHP 8 module.

Now you need to restart Apache for the changes to take effect.

sudo service apache2 restart

Upgrade to PHP 8 for Nginx

For Nginx you need to update the PHP-FPM socket in your Nginx configuration located inside the sites-available directory. This will be located inside the location block location ~ \.php$

Edit your configuration…

sudo nano /etc/nginx/sites-available/your.conf

The line you need to modify will look like this…

fastcgi_pass unix:/run/php/php7.4-fpm.sock;

You need to replace the old PHP version with the new version.

fastcgi_pass unix:/run/php/php8.0-fpm.sock;

Test your configuration and restart Nginx.

sudo nginx -t
sudo service nginx restart

Conclusion

Now you have learned how to install PHP 8 on your Debian server.

Thanks for your time. If you face any problem or any feedback, please leave a comment below.

Disclaimer: Please note that this post includes affiliate links that provide a commission to me. This is at no additional cost to you. If you sign up through our affiliate link, then we get a commission.

--

--

Cloudbooklet

Discover the power of AI, data science, and cloud technology with our insightful blog. Stay ahead of the curve with the latest trends and strategies.