9.2 C
Amsterdam
Wednesday, January 20, 2021

How to install PHP 8 on Ubuntu 20.04 / Debian 10?

Must read

Please Donate

angeloma
angeloma
Senior Writer and partner

Hello, friends. In this post, you will learn how to install PHP 8 on Ubuntu 20.04 / Debian 10. This way, you will be able to take advantage of all the benefits of this programming language that you bring with you in its latest version.

We already know that PHP is the most popular web programming language there is. That is why many developers need to always have the latest version of it to take advantage of the benefits it has to offer.

Install PHP 8 on Ubuntu 20.04

Ubuntu 20.04 was released a few months ago with PHP 7.4 which is still a version with many advantages. In this case, the installation should not be a problem thanks to a PPA.

So, open a terminal and install the following necessary packages:

sudo apt-get install software-properties-common

Then add the repository in question:

sudo add-apt-repository ppa:ondrej/php

After this, refresh APT

sudo apt update

And finally, install PHP 8 and some modules:

sudo apt install php8.0 php8.0-intl php8.0-mysql php8.0-sqlite3 php8.0-gd
Reading package lists… Done
Building dependency tree
Reading state information… Done
The following additional packages will be installed:
apache2 apache2-bin apache2-data apache2-utils fontconfig-config fonts-dejavu-core libapache2-mod-php8.0 libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap
libfontconfig1 libgd3 libjansson4 libjbig0 libjpeg-turbo8 libjpeg8 liblua5.2-0 libtiff5 libwebp6 libxpm4 php-common php8.0-cli php8.0-common php8.0-opcache
php8.0-readline ssl-cert
Suggested packages:
apache2-doc apache2-suexec-pristine | apache2-suexec-custom www-browser php-pear libgd-tools openssl-blacklist
The following NEW packages will be installed:
apache2 apache2-bin apache2-data apache2-utils fontconfig-config fonts-dejavu-core libapache2-mod-php8.0 libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap
libfontconfig1 libgd3 libjansson4 libjbig0 libjpeg-turbo8 libjpeg8 liblua5.2-0 libtiff5 libwebp6 libxpm4 php-common php8.0 php8.0-cli php8.0-common php8.0-gd
php8.0-intl php8.0-mysql php8.0-opcache php8.0-readline php8.0-sqlite3 ssl-cert
0 upgraded, 32 newly installed, 0 to remove and 7 not upgraded.
Need to get 8324 kB of archives.
After this operation, 35.1 MB of additional disk space will be used.
Do you want to continue? [Y/n]

In case you already have it installed, just update the distribution packages:

sudo apt upgrade

Then check the newly installed version:

php -V
PHP 8.0.0RC3 (cli) (built: Oct 31 2020 17:06:41) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.0-dev, Copyright (c) Zend Technologies
with Zend OPcache v8.0.0RC3, Copyright (c), by Zend Technologies

Install PHP 8 on Debian 10

In the case of Debian 10, the process is similar. Only that there is another way to add the repository.

So, open a terminal and install the necessary packages:

sudo apt-get install lsb-release apt-transport-https ca-certificates

Then, add the GPG key of the repository in question.

sudo wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg
--2020-11-25 16:18:36-- https://packages.sury.org/php/apt.gpg
Resolving packages.sury.org (packages.sury.org)… 104.31.95.169, 104.31.94.169, 172.67.182.150, …
Connecting to packages.sury.org (packages.sury.org)|104.31.95.169|:443… connected.
HTTP request sent, awaiting response… 200 OK
Length: 1769 (1.7K) [application/octet-stream]
Saving to: '/etc/apt/trusted.gpg.d/php.gpg'
/etc/apt/trusted.gpg.d/php.gpg 100%[=====================================================================================>] 1.73K --.-KB/s in 0s
2020-11-25 16:18:38 (4.77 MB/s) - '/etc/apt/trusted.gpg.d/php.gpg' saved [1769/1769]

Then add the repository to install PHP 8 on Debian 10 by running the following command:

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

After that, refresh APT

sudo apt update

Now yes, install PHP 8 and some of its modules:

sudo apt install php8.0 php8.0-intl php8.0-mysql php8.0-sqlite3 php8.0-gd
Reading package lists… Done
Building dependency tree
Reading state information… Done
The following packages were automatically installed and are no longer required:
linux-image-4.19.0-5-amd64 linux-image-4.19.0-6-amd64 linux-image-4.19.0-9-amd64
Use 'sudo apt autoremove' to remove them.
The following additional packages will be installed:
apache2 apache2-bin apache2-data apache2-utils libapache2-mod-php8.0 libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap libbrotli1 libcurl4 libicu65
libjansson4 liblua5.2-0 libsodium23 php-common php8.0-cli php8.0-common php8.0-opcache php8.0-readline psmisc
Suggested packages:
apache2-doc apache2-suexec-pristine | apache2-suexec-custom www-browser php-pear
The following NEW packages will be installed:
apache2 apache2-bin apache2-data apache2-utils libapache2-mod-php8.0 libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap libbrotli1 libcurl4 libicu65
libjansson4 liblua5.2-0 libsodium23 php-common php8.0 php8.0-cli php8.0-common php8.0-gd php8.0-intl php8.0-mysql php8.0-opcache php8.0-readline php8.0-sqlite3
psmisc
0 upgraded, 26 newly installed, 0 to remove and 13 not upgraded.
Need to get 16.1 MB of archives.
After this operation, 64.9 MB of additional disk space will be used.
Do you want to continue? [Y/n

Then, check the installed version:

php -v

Output:

PHP 8.0.0RC3 (cli) (built: Nov 3 2020 14:33:19) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.0-dev, Copyright (c) Zend Technologies
with Zend OPcache v8.0.0RC3, Copyright (c), by Zend Technologies

Testing PHP 8

On either system, create a test file

sudo nano /var/www/html/test.php

And add the following code

<?php
phpinfo();
?>

Then save the changes and close the editor.

Next, open your favorite web browser and you will see the PHP information.

1.- PHP 8 on Ubuntu 20.04 / Debian 10
1.- PHP 8 on Ubuntu 20.04 / Debian 10

So, PHP is working. Now you can enjoy it.

More articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

-

Latest article

x