Running Multiple versions of PHP on Windows.
While there are many articles written on how to run multiple versions of PHP on windows, I found out that I quite struggled with the implementation because the procedures were quite long.
Today, I had a necessity to run two PHP versions since v2 of a fintech product we're building runs on PHP 8.1, however, v1 of the same runs on 7.4, I had to support client's requirements on v1.
Installing Two versions of PHP via Xampp:
While Xampp has it's own security disadvantages, It's the fastest way to run make your application up and running since you get PHP, MySQL and Apache in one package.
PHP version 8.1 and 7.4 are in reference to my projects, Substitute with the versions that work for you.
You can Install Xampp by visiting their official website https://www.apachefriends.org/download.html
Configure Environment Variables:
Verify PHP Version:
If you are using PHP and Apache without Xampp then;
Download PHP Versions
Go to the PHP Downloads page https://www.php.net/downloads.php
Download PHP 7.4:
Download PHP 8.1:
Extract the PHP Versions
Configure PHP in Your System
Recommended by LinkedIn
Create Batch Files to Switch PHP Versions
php74.bat:
@echo off
setx PATH "C:\php7;%PATH%"
echo Switched to PHP 7.4
php81.bat:
@echo off
setx PATH "C:\php8;%PATH%"
echo Switched to PHP 8.1
Switch PHP Versions
php74
php81
Verify PHP Version
php -v
Configure Your Web Server
Configure Apache for PHP
# PHP 7.4
LoadModule php74_module "C:/php74/php7apache2_4.dll"
AddHandler application/x-httpd-php .php
PHPIniDir "C:/php74"
# PHP 8.1
LoadModule php_module "C:/php81/php8apache2_4.dll"
AddHandler application/x-httpd-php .php
PHPIniDir "C:/php81"
Following also work in my case https://stackoverflow.com/questions/15617515/windows-command-line-multiple-php-versions