How to Install PHP 8 on Ubuntu 21.04

To Ensure system updated.

apt update

If any update is available update the system and reboot.

apt upgrade -y && reboot

Add PHP PPA Repository

apt -y install software-properties-common

add-apt-repository ppa:ondrej/php


[email protected]:~# add-apt-repository ppa:ondrej/php
PPA publishes dbgsym, you may need to include 'main/debug' component
Repository: 'deb hirsute main'
Co-installable PHP versions: PHP 5.6, PHP 7.x and most requested extensions are included. Only Supported Versions of PHP ( for Supported Ubuntu Releases ( are provided. Don't ask for end-of-life PHP versions or Ubuntu release, they won't be provided.

Debian oldstable and stable packages are provided as well:

You can get more information about the packages at

IMPORTANT: The <foo>-backports is now required on older Ubuntu releases.

BUGS&FEATURES: This PPA now has a issue tracker:

1. If you are using php-gearman, you need to add ppa:ondrej/pkg-gearman
2. If you are using apache2, you are advised to add ppa:ondrej/apache2
3. If you are using nginx, you are advised to add ppa:ondrej/nginx-mainline
   or ppa:ondrej/nginx

PLEASE READ: If you like my work and want to give me a little motivation, please consider donating regularly:

WARNING: add-apt-repository is broken with non-UTF-8 locales, see for workaround:

# LC_ALL=C.UTF-8 add-apt-repository ppa:ondrej/php
More info:
Adding repository.
Press [ENTER] to continue or Ctrl-c to cancel.
Adding deb entry to /etc/apt/sources.list.d/ondrej-ubuntu-php-hirsute.list
Adding disabled deb-src entry to /etc/apt/sources.list.d/ondrej-ubuntu-php-hirsute.list
Adding key to /etc/apt/trusted.gpg.d/ondrej-ubuntu-php.gpg with fingerprint 14AA40EC0831756756D7F66C4F4EA0AAE5267A6C
Get:1 hirsute InRelease [23.9 kB]
Hit:2 hirsute InRelease
Hit:3 hirsute-updates InRelease
Hit:4 hirsute-backports InRelease
Hit:5 hirsute-security InRelease
Get:6 hirsute/main amd64 Packages [36.5 kB]
Get:7 hirsute/main Translation-en [11.4 kB]
Fetched 71.7 kB in 0s (156 kB/s)
Reading package lists... Done

Install PHP 8

Ensure the added package is up to date.

apt update

If any update is available update the system and reboot.

apt upgrade -y && reboot

Install PHP 8 on Ubuntu

apt -y install php8.0

php -v


 [email protected]:~# php -v
PHP 8.0.5 (cli) (built: May  3 2021 11:54:56) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.5, Copyright (c) Zend Technologies
    with Zend OPcache v8.0.5, Copyright (c), by Zend Technologies

To Install php Extensions.

NOTE: Replace the required extensions name in the command

apt install php8.0-<extension>

To list installed php modules/extensions.

php -m

This concludes our topic of installing PHP 8 on the Ubuntu 21.04 system.