How to Upgrade PHP 8.1 to 8.2 in Ubuntu

In my Ubuntu development environment, keeping up with the latest PHP versions is essential to leverage the new features, improvements, and security enhancements introduced in each release. Recently, I encountered the need to upgrade my PHP version from 8.1 to 8.2, and I want to share the process with you through this step-by-step guide.

In this article, I will walk you through the process of upgrading PHP 8.1 to 8.2 in your Ubuntu environment. We will cover all the necessary steps, from checking the currently installed PHP version to upgrading to the latest release using official repositories or third-party tools.

By following this guide, you'll be able to seamlessly upgrade your PHP version and benefit from the latest enhancements in PHP 8.2.

Without further delay, let's dive into the process of upgrading PHP 8.1 to 8.2 in Ubuntu and unlock the potential of the latest PHP version.

Step 1: Check Current PHP Version

Open the terminal on your Ubuntu machine and run the following command to check the currently installed PHP version.

php -v

 

Step 2: Add PHP Repository

To upgrade to PHP 8.2, you need to add the PHP repository to your 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

 

Step 3: Upgrade PHP

Once the repository is added and the system is updated, you can upgrade PHP to version 8.2. Run the following command.

sudo apt install php8.2

During the installation process, you may be prompted to confirm the upgrade and enter your password. Proceed with the installation by following the on-screen instructions.

 

Step 4: Verify PHP Upgrade

After the installation completes, run the following command to verify that PHP 8.2 is installed.

php -v

 

Step 5: Install PHP 8.2 Packages

If you require specific PHP extensions for your projects, you can install them using the apt package manager.

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
 
Step 6: Restart Web Server

If you're using PHP with a web server like Apache or Nginx, restart the webserver to apply the changes

sudo service apache2 restart   # For Apache
sudo service nginx restart     # For Nginx

Note: If it still shows the old PHP version then you can run the below command and choose a new PHP version from their list using the following command.

sudo update-alternatives --config php

Ensure that your web server is using the correct PHP version and test your applications to ensure they are functioning correctly.

 


You might also like: 

techsolutionstuff

Techsolutionstuff | The Complete Guide

I'm a software engineer and the founder of techsolutionstuff.com. Hailing from India, I craft articles, tutorials, tricks, and tips to aid developers. Explore Laravel, PHP, MySQL, jQuery, Bootstrap, Node.js, Vue.js, and AngularJS in our tech stack.

RECOMMENDED POSTS

FEATURE POSTS