Full Stack Developer. DevOps architect.
I love solving problem with code, mainly in web. Often, I make them stylish with css.

How to upgrade from php8.1 to php8.2 in Ubuntu

Recently i upgraded the php version  in 2 of my servers from 8.1 to 8.2. Php 8.2 comes with some nice little  improvements that i  wanted to use like constant in Traits. Here is how it goes:

Adding the correct Repository

To upgrade to PHP 8.2, we need to add the PHP repository to the system. Run the following commands in the terminal to add the repository.

sudo apt install software-properties-common
sudo add-apt-repository ppa:ondrej/php
sudo apt update

Upgrading and necessary packages:

After that , use the upgrade command

sudo apt install php8.2

Hopefully installation finished without any problem. Check the version to see if it outputs 8.2

php -v

In case, it still If it still outputs the old PHP version, we need to run this command   and choose the correct PHP version from the list

sudo update-alternatives --config php

Install the necessary packages to run Laravel 

sudo apt install php8.2-common php8.2-mysql php8.2-xml php8.2-xmlrpc php8.2-curl php8.2-gd php8.2-imagick php8.2-cli php8.2-dev php8.2-imap php8.2-mbstring php8.2-opcache php8.2-soap php8.2-zip php8.2-intl -y

Restart the web server(Apache/nginx)

sudo service apache2 restart 
sudo service nginx restart