PHP 8.2 Released, How to Install in Ubuntu 22.04 | 20.04 via PPA

PHP finally released 8.2.0 release after 7 release candidates. Here are the new features and how to install guide for all current Ubuntu LTS.

PHP 8.2.0 allows to mark a class as readonly, which will add the readonly modifier to every declared property, and prevent the creation of dynamic properties. Moreover, using the AllowDynamicProperties attribute on readonly class will trigger a compile-time error.

Other release highlights in PHP 8.2.0 include:

  • Disjunctive Normal Form (DNF) Types
  • New stand-alone types: null, false, and true
  • New “Random” extension
  • Constants in traits
  • Deprecate dynamic properties

There are as well numerous bug-fixes and other changes in the release. See the changelog for details.

How to Install Php 8.2 in Ubuntu:

Not recommended for beginners. Only install PHP 8.2 for web developing purpose or there’s specific feature or bug-fix you need in this release.

The popular Ondřej Surý’s PPA has built the package for all current Ubuntu LTS: Ubuntu 18.04, Ubuntu 20.04 and Ubuntu 22.04.

1. First, open terminal or connect to your Ubuntu server and run command to add the PPA:

LC_ALL=C.UTF-8 sudo add-apt-repository ppa:ondrej/php

Run sudo apt install software-properties-common in case the command does not exist. And, type user password (no asterisk feedback) when it asks and hit Enter to continue.

2. Then, install Php packages accordingly. For example, install apache2 module and mysql module via command:

sudo apt install php8.2 libapache2-mod-php8.2 php8.2-mysql

Or install the FPM-CGI binary for use with Nginx:

sudo apt install php8.2 php8.2-fpm php8.2-mysql

For Ubuntu 18.04, run sudo apt update first to refresh package cache.

After installed it, remember to configure your http server (apache 2 or nginx) for the new PHP package, and configure php8.2 via files under ‘/etc/php/8.2/’.

Uninstall Php 8.2

To remove the package, simply run command:

sudo apt remove --autoremove php8.2 libapache2-mod-php8.2 php8.2-*

And remove the Ubuntu PPA via command:

sudo add-apt-repository --remove ppa:ondrej/php

Original Article