PHP is widely used in various web development platform in many application or web framework. We also need to update latest PHP version for these various requirements like wordpress, Drupal, and Magento those are some of common examples of web platforms.
Recently PHP has released new version 8 on 26 Nov 2020. So we have might required to update PHP for various application support on their Operating systems, it could Ubuntu or Centos/RHEL machines.

In this post, we will see how we can install PHP8 on Ubuntu 18.04/20.04. Because process for both Os is same, we would work on Ubuntu 18.04 to see its installation, same steps will be used in Ubuntu 20.04 version as well.


Os used during this post is Ubuntu 18.04

ssirohi@srv33:~$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 18.04.5 LTS
Release:        18.04
Codename:       bionic

On Ubuntu 18.04 by default PHP version is 7.2.To install latest PHP version 8 on Ubuntu 18.04 machine , we have to add new repositories (Ondrej PPA), this contain multiple PHP version and extensions.

For same , we have to update and install dependencies first, like below commands

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

Now we need to add Ondrej PPA, with below command.

sudo add-apt-repository ppa:ondrej/php

Here we need to enter for proceed on terminal.

Install PHP 8 version on Ubuntu

As we already added required repositories in Ubuntu machine, we should need to update repositories list like below once.

sudo apt-get update

In case you need to run PHP with Apache web server, we should also install Apache PHP module, like below.

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

To get in effect for Apache Server, we also need to restart Apache Server with below command.

sudo systemctl restart apache2

We can check PHP8.0 version on Machine with simple php command.

root@srv36:~# php -v
PHP 8.0.0 (cli) (built: Nov 27 2020 12:26:05) ( 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

For installing various php extension on Ubuntu machine with same apt-get command, below are some examples for same.

apt install php8.0-Extension-Name

There are various php8.0 extension with this repository like below.

root@srv33:~# apt-cache search php8.0-redis
php8.0-redis - PHP extension for interfacing with Redis
root@srv36:~# apt-cache search php8.0-| wc -l