PHP Debug And Test Your Code Against Different PHP Versions – PHP Version Change Tips

As a developer, you probably require different PHP versions that you can easily change at a click of a button, and to run tests of your code base and simulate different server environments. Problem arises when your hosting offers only selected minor versions (e.g. 5.0, 5.1, 5.2, 5.3, 5.4, 5.5, 5.6, 7.0, 7.1 etc.), but not particular patch versions (e.g. 5.3.5, 5.4.16, 7.0.5, 7.1.13 etc.) that some still might use.

In this case, you will not be able to simulate exact conditions in your lab, and you’ll have to get the same hosting or server plan, just to be able to run the tests. Is there a better way?

HOW TO CHANGE PHP VERSION FOR DEVELOPMENT TESTING?

Of course, many use Docker or some hosting plans that provide an easy way of changing PHP via cPanel, however, the problem with sub-minor versions availability still holds. To circumvent this, you can install manually ANY particular version you require in your environment.

cPanel PHP Selector & Extensions - How To Change PHP Version

cPanel PHP Selector & Extensions – How To Change PHP Version

As we mainly develop under Windows (which shouldn’t come as a surprise btw., just take a look at the latest Stack’s Survey), occasionally we need flexibility to run tests under different PHP versions and check if something stands out and fix it.

1. Download XAMPP version from archive @ SourceForge

https://sourceforge.net/projects/xampp/files/

For older versions, you need to use 1.x branches of XAMPP (1.7x, 1.8x for example) and they ship in x86 architecture, using PHP 5.3x / 5.4x. For newer versions, obviously, download newer XAMPP edition, there are also portable ones, which we like the most.

Unzip it, usually @ C:\ drive, and enjoy.

2. Change PHP version

To actually change PHP version, go to windows compiled DLL archives here, and download one that you need:

http://windows.php.net/downloads/releases/archives/

VC6 – very old PHP versions
VC9 – up to 5.4.x versions
VC11 – PHP 5.5/5.6 versions
VC14 – PHP 7.x versions

(and so on)

Mind you, you cannot always change whatever PHP version you like with any XAMPP edition, you will have to pair them to a certain level, and make sure everything still works.

We haven’t tried it, but the same trick should be possible on Linux and Mac, as XAMPP supports all three major platforms now.

Lastly, one important thing you should always keep in mind and be aware of when developing PHP applications under Windows stacks (XAMPP, WAMP, etc.):

DLLs are not exactly the same with their Linux counterparts. For example, if you update core PHP library DLLs, some other modules (extensions / libraries) like libssh2.dll, php_curl.dll, php_imagick.dll etc. should be installed and updated, too. It is not always as convenient to replace them, or even find appropriate compiled versions on the web for particular PHP version.