- Published on
Running multiple PHP versions in Ubuntu
- Authors
- Written by :
- Name
- Varun Kumar
There are times when you want to run multiple PHP versions in your system, maybe because you are working on multiple projects that requires different PHP versions, or your operating system installs the PHP version provided by the official PPA repositories of your system. Let's see how we can install and run multiple PHP versions in the same system.
Step 1: Adding PHP's PPA in the system
Adding ondrej/php
in your system allows providing more up-to-date information of the latest PHP versions available to install:
sudo add-apt-repository ppa:ondrej/php
After adding the PPA, update the repositories of your system:
sudo apt update -y
Step 2: Installed the required PHP version and it's libraries
You can now install required PHP along with PHP libraries of same version. Example:
sudo apt install php7.0 php7.0-fpm php7.0-mysql
or
sudo apt install php8.1 php8.1-fpm php8.1-mysql
Step 3: Activate desired PHP version on CLI
If you wish to use PHP on CLI, you can list and activate your desired PHP version.
sudo update-alternatives --config php
This command shows all the installed and currently active PHP version. You can select the PHP version you want to activate on CLI by supplying the suitable Selection number: