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:
- 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
- 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
- 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).
- 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.
- Verify PHP installation
Verify that PHP was installed correctly by running the following command:
You should see the version of PHP that you installed.OutputPHP 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
Switch Between Multiple PHP Versions
You can use
`update-alternatives` command to set or change the default PHP version.
sudo update-alternatives --config php
The command will list all installed PHP versions on your system. From which you can set the default PHP version.
There are 3 choices for the alternative php (providing /usr/bin/php). Selection Path Priority Status ------------------------------------------------------------ * 0 /usr/bin/php8.2 82 auto mode 1 /usr/bin/php7.4 74 manual mode 2 /usr/bin/php8.1 81 manual mode 3 /usr/bin/php8.2 82 manual mode Press
to keep the current choice[*], or type selection number:
Input a selection number to set default PHP version for the command line.
Note: This will not change the default PHP version for Apache.
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.