If you want to develop web applications using PHP on Pop!_OS, you may need to install multiple versions of PHP for testing or compatibility purposes. One way to install multiple versions of PHP on Pop!_OS is to use a Personal Package Archive (PPA). At the day of writing this tutorial PHP 8.2 is the latest version available.

In this article, we will discuss the steps for installing PHP 8.2, PHP 8.1 or PHP 8.0 versions on Pop!_OS using a PPA.

Steps to Install PHP on Pop!_OS

To install PHP on Pop!_OS using a Personal Package Archive (PPA), you can follow these steps:

  1. Install required packages

    Open a terminal and install the software-properties-common package, which provides the “add-apt-repository” command that you will use to add the PPA:

    sudo apt update 
    sudo apt install software-properties-common 
    
  2. Add the Ondřej Surý PPA

    Add the Ondřej Surý PPA, which provides updated versions of PHP:

    sudo add-apt-repository ppa:ondrej/php
    

    Update the package list again to include the packages in the PPA:

    sudo apt update
    
  3. Installing PHP 8 on Pop!_OS

    Now, execute the following command to install PHP using the apt package manager:

    sudo apt install php8.2
    

    Replace “8.2” with the desired version of PHP like “8.1”, “8.0”, “7.4” or “5.6”. This will also install the PHP package manager “composer” (PHP Package Manager).

  4. Install PHP modules

    You can also install the PHP modules that is required for your application. The below given command will install mysql, zip and curl php modules.

    sudo apt install php8.2-mysql php8.2-zip php8.2-curl 
    

    Make sure to use correct php version with command.

  5. Verify PHP installation

    Verify that PHP was installed correctly by running the following command:

    php -v 
    

    You should see the version of PHP that you installed.

    Output

    PHP 8.2.1 (cli) (built: Jan 13 2023 10:43:08) (NTS) Copyright (c) The PHP Group Zend Engine v4.2.1, Copyright (c) Zend Technologies with Zend OPcache v8.2.1, Copyright (c), by Zend Technologies

Conclusion

Installing multiple PHP versions on Pop!_OS using a PPA involves adding the PPA to your system, updating the package list, and installing the desired PHP version using the apt package manager. This is a relatively easy way to install PHP, but it is important to note that using a PPA can introduce compatibility issues and security risks. It is generally better to use the Pop!_OS package manager or install PHP from source. Regardless of which method you choose, it is important to keep your PHP installation up to date to ensure security and compatibility.