Tested on: Ubuntu 22.04

Default php version is 8.1 and we want install php 7.4

Ondrej PPA contains PHP 8.2, 8.1, 8.0, 7.4, 7.3, 7.2, 7.1, 7.0 & PHP 5.6 packages.

First update the system

1. Check Active PHP Version

2. Install php on system

Set the required PPA wich contains any PHP version.

 
  1. Install dependancy:
  2. Enable Ondrej PPA 
  3. Update the Apt package manager cache.
  4.  PHP versions on your system.
    • Install PHP 7.4:

    You can install multiple PHP versions on a single Ubuntu system.

 

  1. PHP applications depend on various extensions to extend their features. That can also be installed using the following syntax:

    for example:

    Users who have installed different PHP versions, need to replace 8.2 with the required PHP versions.

 

3. Choose Default PHP Version 

with update-alternatives command you can set the default version you want to be active in your system

4. Removing PHP

If you want to remove the php version 8.1 from your system you can do:

Also, uninstall all the modules for that version with the following command: