Connect with us

Linux

How to install PHP 8.0 on Ubuntu 20.04

PHP is a popular server-side scripting language that is used for developing dynamic websites. PHP 8.0 was released on November 26, 2020, and packs with major improvements and enhancements. We have previously shown you how to install PHP 8.0 on CentOS 8. In this guide, we cast our net wider and show you how to install PHP 8.0 on Ubuntu 20.04 Focal Fossa. Let’s begin!

Step 1: Update Ubuntu 20.04

The first step is to update your system’s package lists and repositories. To achieve this, log in as a sudo user and execute the command:

With the system up to date, now let’s proceed to the next step.

Step 2: Add the Ondřej Surý P.PA repository

In Ubuntu 20.04 repositories, PHP 7.4 is the default PHP version at the time of penning this guide. But since we are interested in installing PHP 8.0, we will add the Ondřej Surý PPA repository which packs dozens of PHP versions. To achieve this, run the command:

When prompted to continue with the installation, simply hit the ‘ENTER‘ button on your keyboard. This takes a couple of seconds.

Step 3: Install PHP 8.0 on Ubuntu 20.04

After adding the Ondřej Surý PPA repository, update the package lists on your system as follows:

If you have an instance of Apache webserver running on your system, run the command below to install PHP 8.0 and the PHP Apache module.

Then restart the Apache webserver to enable the module.

If you intend to use the PHP-FPM ( FastCGI Process Manager), then issue the command below to install the required modules:

Thereafter, enable the module by executing the commands shown:

Then restart Apache to enable the changes:

Step 4: Install PHP 8.0 with Nginx

If on the other hand, you are running an Nginx web server on your server, the recommended way is to install PHP-FPM. PHP-FPM is an alternative implementation of PHP that packs with additional features to support highly-loaded websites.

To install PHP-FPM, execute the command:

 install PHP 8.0 on Ubuntu

After the installation is complete, PHP-FPM should start automatically, you can confirm this using the command:

Check status of PHP-FPM

For the Nginx webserver to process PHP files, update your Nginx server block by appending the server section with the lines below:

server { # … some other code location ~ \.php$ { include snippets/fastcgi-php.conf; fastcgi_pass unix:/run/php/php8.0-fpm.sock; }

Then restart the Nginx web server for the changes to kick in.

Step 5: Test PHP installation

To check the PHP version installed, execute:

Check PHP version installed

Also, you can test the PHP version on a browser. To do this, create a sample PHP file at the webroot directory.

Add the lines below.

<?php phpinfo(); ?>

Proceed to your browser and browse your server’s IP address as shown:

You should get the information below displaying the PHP version and other server details.

Ladies and gentlemen. We have come to the end of our article. And that’s how you install PHP 8.0 on Ubuntu 20.04.

Continue Reading
Advertisement

Trending