Home  »  ArticlesGuidesHow ToLibrariesTechnology   »   How To Install PHP 8.2 on Ubuntu 22.04|20.04|18.04

How To Install PHP 8.2 on Ubuntu 22.04|20.04|18.04

Today we will be showing you how to install PHP 8.2 on Ubuntu 22.04, 20.04, or 18.04 Linux systems. For those looking for other distros, we have a tutorial on installing PHP 8.2 on Debian systems and another one for CentOS 7 and RHEL 7 distros.

PHP 8.2 is the current version of the PHP programming language released in December 2022 with many new features as highlighted below:

  • Readonly Classes: A class can be declared as readonly, making all of its properties to be automatically declared readonly
  • Type System Improvements: Added support for true type, and allowing null and false types to be used as stand-alone types as well as support for DNF types.
  • New random extension: This new feature provides a new OOP API to generate random numbers with a pluggable architecture.
  • Constants in Traits: It is now possible to declare constants in traits in In PHP 8.2.
  • Sensitive Parameter Value Redaction: This feature adds new built-in parameter Attribute named #[\SensitiveParameter] that ensures PHP redacts the actual value in stack traces and error messages.
  • New Functions and Classes: New classes and functions such as ini_parse_quantity, curl_upkeep, openssl_cipher_key_length, and memory_reset_peak_usage are now included.
  • Dynamic Properties Deprecated : In PHP 8.2 class properties that are dynamically declared
  • utf8_encode and utf8_decode Functions are now deprecated.

Step 1. Add Sury PPA repository

Add the PPA that contains the latest PHP packages. Install dependency packages for this.

$ sudo apt update
$ sudo apt install lsb-release apt-transport-https ca-certificates software-properties-common -y

Install the tool to get the release.

$ sudo apt install lsb_release

Now we add ondrej/php to the repositories.

$ sudo add-apt-repository ppa:ondrej/php
$ sudo apt update

Step 2. Install PHP 8.2 on Ubuntu 22.04|20.04|18.04

Run the following command to install PHP 8.2.

$ sudo apt install php8.2

Confirm and check the version of PHP currently installed on the system run the following command:

$ php -v


PHP 8.2.1 (cli) (built: Jan 13 2023 10:43:08) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.2.1, Copyright (c) Zend Technologies
    with Zend OPcache v8.2.1, Copyright (c), by Zend Technologies

Step 3. Install PHP 8.2 extensions

You can now install the PHP 8.2 extensions that you require. PHP extensions are libraries that provide extra functionality to the PHP programming language.

To install a PHP extensions you would need to run a command with the following syntax:

sudo apt install php8.2-<extension-name>

For example, assuming we want to install the following PHP extensions:

bz2, cli, common, curl, intl, mbstring, mysql, zip

The we would run the following command to install the above extensions:

$ sudo apt install php8.2-{bz2,cli,common,curl,intl,mbstring,mysql,zip}

We have prepared a more comprehensive article showing how to install PHP modules in Ubuntu if you need more details.


You now know how to install Install PHP 8.2 on Ubuntu 22.04|20.04|18.04 Linux systems. We have also shown you how to install PHP8.2 extensions to get the functionality you need. If you need to run your PHP with Nginx or Apache web servers, we have a tutorial showing you how to use PHP 8.2 with Nginx / Apache web servers.

Found this article interesting? Follow Brightwhiz on Facebook, Twitter, and YouTube to read and watch more content we post.