How to use different versions of PHP? [duplicate]

Solution 1:

Maybe not the response that you're waiting for, but it gets painful to manage several php versions in your machine.

I've found that the best approach is to have a newer php version (php7+) as primary, and if I need something older or another specific version, I use a container with apache/php from here or use this as base image and modify it as necessary, it has great instructions to do that.

In the case that I need an older php version (unsupported so be careful), I can just build from an older OS version with support for that particular version.

The advantages of this approach are, first, that you don't mess up your machine with lots of packages and dependencies. Second, you don't pollute your php install with all the dependencies and packages that eventually will conflict with each other due to version-incompatibility. Finally, and super importantly, dockerizing apps will give you a replicable recipe for your production environment.

Even if you don't choose this as your approach, take a look at docker. It will make your like easier and it's "the thing" used in development nowadays.