Website Vidya
DeploymentStep-by-Step Guide

How to Upgrade PHP 8.2 to 8.3 in Ubuntu: 8 Easy Steps

Are you ready to take your PHP environment to the next level? Upgrading your PHP version is not just a routine task—it’s an opportunity to harness the latest features, enhanced performance, and fortified security measures that come with PHP...

RR
Website Vidya TeamLead Systems Educator
Published:
5 min read
How to Upgrade PHP 8.2 to 8.3 in Ubuntu: 8 Easy Steps
AI Executive SummaryCORE CIS AI

5 min read

Are you ready to take your PHP environment to the next level? Upgrading your PHP version is not just a routine task—it’s an opportunity to harness the latest features, enhanced performance, and fortified security measures that come with PHP...

Key Highlights
  • How to Install Multiple PHP Versions on Ubuntu 22.04
  • Conclusion
Grounded in full engineering runbookCORE CIS Ai Engine

Managing multiple PHP versions on a single server is essential when working on different projects requiring different PHP environments. In this article, we'll walk you through a detailed step-by-step guide on how to install multiple PHP versions on Ubuntu 22.04. We'll use the widely trusted Ondrej PPA repository to make this process straightforward and efficient.

By following this tutorial, you'll be able to install, configure, and switch between PHP versions seamlessly on your system. This guide also works for Ubuntu 20.04 and 18.04.

How to Install Multiple PHP Versions on Ubuntu 22.04

Step 1: Update the System

Before installing any software, it’s a best practice to update your system to ensure that you’re working with the latest package versions. Open a terminal and run the following commands:

sudo apt-get update
sudo apt-get upgrade

Step 2: Add the Ondrej PHP Repository

The Ondrej PPA is a popular repository that contains various PHP versions and related packages. To enable it, execute these commands:

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

Step 3: Install Multiple PHP Versions

With the Ondrej repository enabled, you can now install different PHP versions. Below are the commands for installing PHP 8.1, PHP 8.0, and PHP 7.4 along with their common extensions.

Install PHP 8.1

To install PHP 8.1, run:

sudo apt-get install php8.1 php8.1-fpm
sudo apt-get install php8.1-mysql php8.1-mbstring php8.1-xml php8.1-gd php8.1-curl

Install PHP 8.0

To install PHP 8.0, execute:

sudo apt-get install php8.0 php8.0-fpm
sudo apt-get install php8.0-mysql php8.0-mbstring php8.0-xml php8.0-gd php8.0-curl

Install PHP 7.4

For PHP 7.4, use:

sudo apt-get install php7.4 php7.4-fpm
sudo apt-get install php7.4-mysql php7.4-mbstring php7.4-xml php7.4-gd php7.4-curl

You can repeat this process for any other PHP versions you need, such as PHP 7.3 or PHP 5.6, by replacing the version number in the above commands.

Step 4: Check the Active PHP Version

To check the currently active PHP version, use:

php -v

This will display the default PHP version set for the CLI (Command Line Interface).

Step 5: Switch Between PHP Versions

Ubuntu allows you to switch the default PHP version using the update-alternatives command. Run the following:

sudo update-alternatives --config php

You’ll see a menu listing all installed PHP versions. Enter the number corresponding to the version you want to set as the default and press ENTER.

Alternatively, to switch directly to a specific version, use:

sudo update-alternatives --set php /usr/bin/php7.4

Step 6: Configure PHP-FPM

If you’re using a web server like Apache or Nginx, you’ll need to configure it to use the appropriate PHP-FPM version. For example, in Nginx, edit your virtual host configuration to point to the desired PHP-FPM socket:

server {
listen 80;
server_name example.com;

root /var/www/html;
index index.php index.html;

location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php8.1-fpm.sock;
}
}

Restart Nginx to apply the changes:

sudo systemctl restart nginx

Step 7: Uninstall PHP Versions

If you need to remove a specific PHP version, use the following command:

sudo apt-get remove php7.4

To remove all modules associated with that version, run:

sudo apt-get remove php7.4-*

Finally, clean up unused dependencies:

sudo apt-get autoremove

Conclusion

Installing and managing multiple PHP versions on Ubuntu 22.04 is straightforward when using the Ondrej PPA repository. Whether you’re a developer juggling projects with different PHP requirements or someone setting up a robust web development environment, this guide equips you to handle PHP versions efficiently.

Now that you know how to install multiple PHP versions on Ubuntu 22.04, go ahead and set up your system to meet your project’s needs!

Have any questions or face any challenges?

Drop them in the comments below!

Written by

Website Vidya Team

Technology educator and researcher at Website Vidya.

Discussion

0
Share your thoughts, ask a question, or suggest a tip...
Write →

No comments on this guide yet. Be the first to share your thoughts or ask a question!

Recommended Reading10 Guides

Related Technical Guides

Tested runbooks, server administration walkthroughs, and troubleshooting guides

Deployment•

How to Install PDO Extension in PHP

PHP Data Objects (PDO) is one of the most important extensions in PHP for working with databases in a secure, consistent, and modern way. If you are building dynamic websites, APIs, CMS platforms, or enterprise applications, PDO is not opti...

RR
Rajesh Rai
Read More
Deployment•

25 Best Linux Commands Every Sysadmin Should Know

If you’ve spent any time managing Linux servers, you already know this truth: the command line is not optional. It’s where real troubleshooting happens, where performance issues are understood, and where outages are prevented before users e...

RR
Rajesh Rai
Read More
Deployment•

How to Fix Snapd Consuming High CPU / RAM on Linux

If you’ve ever opened your system monitor and noticed snapd quietly eating up your CPU or RAM, you’re not alone. Many Linux users—especially on Ubuntu and Ubuntu-based distributions—eventually run into this issue and wonder what’s going on ...

RR
Rajesh Rai
Read More