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

  • Install Xampp which has PHP version 8.1 and save it in your local disk C, you can rename it to xampp81.
  • Install Xampp which has PHP version 7.4 and save it in your local disk C, you can rename it to xampp74.

Configure Environment Variables:

  • Right-click on This PC or Computer and select Properties.
  • Click on Advanced system settings and then on the Environment Variables button.
  • Find the Path variable in the System variables section, select it, and click Edit.
  • Add the paths to your PHP installations to the Path variable. Ensure the path to PHP 7.4 is listed before the path to PHP 8.1 if you want PHP 7.4 to be the default version, vice versa is also true.

Verify PHP Version:

  • Open a new command prompt and run PHP -v to check the current PHP version. It should display PHP 7.4.
  • To switch to PHP 8.1, you can temporarily change the path within your command prompt session: set PATH=C:\xampp81\php;%PATH%


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

  • Create PHP Directories:
  • Create directories for each PHP version, for example, C:\php74 and C:\php81
  • Extract the ZIP Files:
  • Extract the contents of each downloaded zip file into their respective directories (C:\php74 and C:\php81).

Configure PHP in Your System

  • Add PHP to System Path:
  • Go to Control Panel > System and Security > System > Advanced system settings.
  • Click on Environment Variables.
  • In the System variables section, find the Path variable and click Edit.
  • Add the paths to both PHP directories (C:\php74 and C:\php81) to the list.

Create Batch Files to Switch PHP Versions

  • Create Batch Files:
  • Open a text editor and create two batch files, one for each PHP version.

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        

  • Save the files:
  • Save php74.bat and php81.bat in a directory that’s included in your system’s PATH.

Switch PHP Versions

  • Open Command Prompt as Administrator:
  • To switch to PHP 7.4, type:

php74        

  • To switch to PHP 8.1, type:

php81        

Verify PHP Version

  • After switching, verify the PHP version by typing:

php -v        

Configure Your Web Server

Configure Apache for PHP

  • Open the Apache configuration file (httpd.conf) located in your Apache installation directory.
  • Add the following lines to the httpd.conf file to point to the desired PHP version:

# 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"
        

  • Comment out one of the versions based on your current need.
  • Restart the Apache service to apply the changes.

To view or add a comment, sign in

More articles by Celine Bowen

  • Cohesion in Software Architecture

    Cohesion is a crucial concept in software architecture, particularly when we are referencing modularity. It refers to…

    3 Comments

Others also viewed

Explore content categories