How To Install PHP 8.0 on Debian 10 / Debian 9 | Holhol24
PHP is an open-source programming language used for web development, created by Rasmus Lerdorf in 1994. It is an HTML-embedded scripting language for creating dynamic websites such as blogs, internet forums, e-commerce portals, etc.
In this post, we will see how to install PHP 8.0 on Debian 10 / Debian 9.
Add PHP Repository
SURY, a third-party repository that offers PHP 8.0/7.x for the Debian operating system. Update the repository cache.
sudo apt update
Install the below packages.
sudo apt install -y curl wget gnupg2 ca-certificates lsb-release apt-transport-https
Import the public using the below commands.
wget https://packages.sury.org/php/apt.gpg sudo apt-key add apt.gpg
Add the SURY repository to your system.
echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" | sudo tee /etc/apt/sources.list.d/php8.list
Update the repository index.
sudo apt update
Install PHP
Install PHP 8.0 on Debian 10 / Debian 9
Install PHP v8.0 with the following command.
sudo apt install -y php8.0 php8.0-cli php8.0-common
Install PHP 7.x on Debian 10 / Debian 9
Install PHP v7.4 with the following command.
sudo apt install -y php7.4 php7.4-cli php7.4-common
You can also have multiple PHP versions on your system. Each PHP version will have separate configuration files under /etc/php/{8/7}.X directory.
Set Default PHP Version
You can set the default PHP version with the below command if your system has multiple PHP versions. Change php8.0 with the version you want to set as the default PHP version.
sudo update-alternatives --set php /usr/bin/php8.0
Check PHP Version
Once you installed the PHP, check the version.
php -v
Output:
PHP 8.0.0 (cli) (built: Nov 30 2020 20:40:07) ( NTS ) Copyright (c) The PHP Group Zend Engine v4.0.0-dev, Copyright (c) Zend Technologies with Zend OPcache v8.0.0, Copyright (c), by Zend Technologies
PHP Support for Web Server
Both Apache and Nginx do not support PHP language processing by default when the browser requests the PHP page. So, we need to install the PHP package on the server to support PHP files.
PHP Support for Apache
Install the below package with Apache webserver to support PHP. This package provides the PHP modules for Apache 2 web server. Change the PHP version, if required.
sudo apt install -y apache2 libapache2-mod-php8.0
PHP Support for Ngnix
Nginx does not have a PHP modules package to support PHP. But, we can use the PHP FastCGI Process Manager to handle PHP requests. Change the PHP version, if required.
sudo apt install -y php8.0-fpm
Once you have installed FastCGI manager, add socket details in Nginx virtual host.
server { # other codes location ~* .php$ { fastcgi_pass unix:/run/php/php8.0-fpm.sock; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param SCRIPT_NAME $fastcgi_script_name; } }
Install PHP Extensions
PHP extensions enable specific functions/support for your written code. For example, installing PHP MySQL extension will let your PHP code to connect with the MySQL database.
PHP extensions package is normally named like php-.
To install MySQL support for PHP v8.0, you can install php8.0-mysql
package.
sudo apt install -y php8.0-mysql
Once you have installed a required extension, use the below command to verify it.
php -m | grep -i mysql
Output:
mysqli
mysqlnd
pdo_mysql
Conclusion
That’s All. Please share your feedback in the comments section.