How to install multiple PHP versions on Linux

Did you know that it is possible to install and manage multiple PHP versions on your Linux operating system ? Did you know that you can manage more than one PHP version on your system ?

In this article, you are going to be discovering everything you need to know on how to install and manage multiple PHP versions on Debian based Linux distributions.

As you know, PHP is one of the most powerful and popular programming languages when it comes to building scalable and secure websites and web applications. It is used by popular web frameworks such as Laravel and Symfony.

By default, on Linux, you are able to install only one version of PHP at the same time. If you try to install another PHP version, it will automatically overwrite the previous one.

I’m going to be showing you step by step what you have to do to give your Linux system the ability to install and manage multiple PHP versions.

So, without further ado, let’s get started guys…

Step 1. The first thing you have to do is to install a third-party software or package that will allow you to add to your system a repository that contains other PHP versions. In this way, your system will not have only one PHP version to install but multiple ones.

The third-party package that you need to install is called software-properties-common.

To do so, open your terminal and run the following command :

Step 2. Once the software is installed, you next have to add to your system a third-party repository created by ondrej, that contains multiple PHP versions.

In your terminal, run the following command to add to your system a repository for PHP and another one for Apache :

Step 3. Once the external repositories are added to your system, you need to update your APT packages list so that those repositories will be ready to be used.

To do so, you will have to run the following commands in your terminal :

Step 4. Now, everything is ready. You are ready to install and manage multiple PHP versions on your system. Notice that you can install whatever PHP version you want… An old PHP version than your current installed version or a newer version.

Suppose you have the 7.4 PHP version already installed on your system and you want to additionally install the versions 7.3 and 8.1.

Open your terminal and run the two following commands to install the 7.3 and 8.1 PHP versions :

Notice that the installation of these additional versions will not overwrite the current version 7.4, they will just be added on top of it. As I told you before, it’s the software-properties-common package that gives your system this ability.

Now, you have three PHP versions installed on your system (7.3, 7.4 and 8.1). To show or list them, you can run the following command in your terminal :

Three PHP versions are installed on the system.

If you want to see the current version selected by your system, run the the following command in your CLI :

The current selected PHP version is 7.4

After running the above command, you will see a list of all the installed PHP versions, and the number of selected version will be preceded by an asterisk sign *.

If you want to change or switch to another PHP version (the 8.1 for example), just type its number (in our case number 0 or 3), then press Enter to confirm changes.

Congratulations, you did it. Now you have the ability to install multiple PHP versions and manage them on your Linux operating system. I’m so proud of you 🥰

That’s all for today’s article guys. If you have any question or reaction about what was said, feel free to use the comment section to express yourself; and don’t forget to give me a clap if the article was useful for you !

--

--

Hey there, I’m Donatien Vamuleke. I love dealing with technology, having high value conversations with people and turning my ideas into writings.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Donatien Vamuleke

Hey there, I’m Donatien Vamuleke. I love dealing with technology, having high value conversations with people and turning my ideas into writings.