PHP 8.0, how to install this language in Ubuntu 20.04

about php 8.0

In the next article we will take a look at how can we install PHP 8.0 using Ubuntu 18.04 or 20.04 with Apache. This is a popular language for web development originally created in 1994 by Rasmus Lerdorf, a Danish-Canadian programmer. It is the language used to develop responsive and dynamic websites. In fact, platforms CMS Popular like WordPress, Drupal and Magento are based on PHP.

The created PHP files can run on Gnu / Linux, macOS, Windows and many other Unix systems, provided PHP has been installed. In the following lines we are going to see how we can install PHP 8.0 in Ubuntu 20.04.

General features of PHP 8.0

The latest version to this day of PHP is PHP 8.0 and was released on November 26, 2020. In it you can find many new features. PHP 8.0 is a major update to the PHP language that contains new features and optimizations. Among them we can find:

  • This version only specifies the required parameters, skip the optionals. The arguments are independent of order and are automatically documented.
  • Attributes Instead of annotations in PHPDoc, we can use structured metadata.
  • We will need less code to define and initialize a property.
  • We can use a native union type declaration which will be validated at the time of execution.
  • Match expressions. The new match expressions are similar to switch and have the following characteristics like; Match is an expression, which means that it can be stored as variables or returned. It also makes strict comparisons.
  • Nullsafe operator. Instead of checking for null conditions, users can use a string with the new nullsafe operator. When the evaluation of an element fails, the execution of the chain is aborted and evaluated as null.
  • Smart comparisons between strings and numbers.
  • Most internal functions now provide an exception error if the parameter is not validated.

These are just some of the features of PHP 8.0. Can be consult all of them in detail from the

Install PHP 8.0 on Ubuntu

Add the PPA

PHP 7.4 is the default version in the Ubuntu 20.04 repositories at the time of this writing. In order to install the latest version of PHP we will need to use the Ondrej PPA repository. It contains multiple versions and extensions of PHP.

Before proceeding with the installation we will have to open a terminal (Ctrl + Alt + T) and update system packages. We will also install some dependencies.

sudo apt update; sudo apt upgrade

install php 8 dependencies

sudo apt install ca-certificates apt-transport-https software-properties-common

After the installation of the dependencies, we can add the Ondrej PPA. In the same terminal, we will only need to use the command:

add repository for php 8.0

sudo add-apt-repository ppa:ondrej/php

Install PHP 8.0 on Apache

After adding the PPA in our team, it should occur updating packages available from repositories.

installed version of apache2

If you are running an Apache web server, you can proceed to install PHP 8.0 with the Apache module. To do this, you just have to open a terminal (Ctrl + Alt + T) and execute the command:

install php 8 on apache2

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

Once the installation is finished, we will have to restart Apache web server to enable the module.

sudo systemctl restart apache2

At this point, we can confirm the default PHP version on the server:

php apache version

php -v

If you are interested in using the Apache web server with PHP-FPM, run the following command to install the necessary packages:

install php fpm

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

Given the PHP-FPM is not enabled by default, we will have to enable it with the following commands:

enable php fpm

sudo a2enmod proxy_fcgi setenvif

sudo a2enconf php8.0-fpm

Then we will have to go back to restart the Apache web server for the changes to take effect:

sudo systemctl restart apache2

Install PHP 8 extensions

PHP extensions are libraries that extend the functionality of PHP. These extensions exist as packages and can be installed as follows:

sudo apt install php8.0-[nombre-de-extension]

Verify installation

To confirm the version of PHP installed, from the graphical environment we can create a php file in / var / www / html called info.php:

sudo vim /var/www/html/info.php

Inside the file, we will only have to paste the following lines and save the file.




Finally, in our favorite web browser we are going to write the server’s IP address in the URL and the name of the newly created file:


When accessing this small file, if everything is correct we should see the following screen:

php8 in apache

And with this we can consider PHP 8.0 installed and integrated with the Apache web server running on Ubuntu 20.04.

Add Comment