Skip to content

Instantly share code, notes, and snippets.

@powertech2nd
Last active March 2, 2026 14:15
Show Gist options
  • Select an option

  • Save powertech2nd/2435b3bd91e7a5848548cb3625eed608 to your computer and use it in GitHub Desktop.

Select an option

Save powertech2nd/2435b3bd91e7a5848548cb3625eed608 to your computer and use it in GitHub Desktop.
Running multiple PHP on XAMPP windows

Run Multiple PHP Versions in a Single XAMPP Installation (Windows)

With a single XAMPP installation, you have 3 options to run multiple PHP versions:


✅ Option 1 — Run an Older PHP Version for Specific Directories

This is the most common use case.

You may have one or two old projects that require an older PHP version.
You can configure XAMPP to run that older PHP version only for specific project directories.


✅ Option 2 — Run an Older PHP Version on a Separate Port

Useful when:

  • You are upgrading an old project
  • You need to test the same project in both old and new PHP versions

Example:

  • http://localhost/any_project/ → runs PHP 7
  • http://localhost:8056/any_project/ → runs PHP 5.6

✅ Option 3 — Run an Older PHP Version on a Virtual Host

You can create a virtual host like:

  • http://localhost → PHP 7
  • http://localhost56 → PHP 5.6

Step-by-Step Setup Guide


1️⃣ Download PHP

Assume:

  • XAMPP is running PHP 7
  • You want to add PHP 5.6

Steps:

  1. Download the NTS (Non-Thread-Safe) version from:

  2. Extract it to:

C:\xampp\php56

⚠️ Important:
The Thread-Safe version does NOT include php-cgi.exe, which we need.


2️⃣ Configure php.ini

Open:

C:\xampp\php56\php.ini

If it does not exist:

  • Copy php.ini-development
  • Rename it to php.ini

Then make sure this line is uncommented:

extension_dir = "ext"

Apache Environment Variable Fix

Open:

C:\xampp\apache\conf\extra\httpd-xampp.conf

If this line exists:

SetEnv PHPRC "\\xampp\\php"

Comment it out:

#SetEnv PHPRC "\\xampp\\php"

3️⃣ Configure Apache

Open XAMPP Control Panel:

  • Click Config (Apache)
  • Open httpd-xampp.conf

Add this at the bottom of the file:

ScriptAlias /php56 "C:/xampp/php56"
Action application/x-httpd-php56-cgi /php56/php-cgi.exe

<Directory "C:/xampp/php56">
    AllowOverride None
    Options None
    Require all denied
    <Files "php-cgi.exe">
        Require all granted
    </Files>
</Directory>

💡 You can repeat this process for additional PHP versions (php54, php74, etc.)


OPTION 1 — Run PHP 5.6 for Specific Directories

Add this to the bottom of httpd-xampp.conf:

<Directory "C:\xampp\htdocs\my_old_project1">
    <FilesMatch "\.php$">
        SetHandler application/x-httpd-php56-cgi
    </FilesMatch>
</Directory>

<Directory "C:\xampp\htdocs\my_old_project2">
    <FilesMatch "\.php$">
        SetHandler application/x-httpd-php56-cgi
    </FilesMatch>
</Directory>

Now only those directories will use PHP 5.6.


OPTION 2 — Run PHP 5.6 on a Separate Port

To run PHP 5.6 on port 8056, add:

Listen 8056

<VirtualHost *:8056>
    <FilesMatch "\.php$">
        SetHandler application/x-httpd-php56-cgi
    </FilesMatch>
</VirtualHost>

Now:

  • http://localhost/project → Default PHP
  • http://localhost:8056/project → PHP 5.6

OPTION 3 — Run PHP 5.6 on a Virtual Host

Step 1 — Create Directory

Create:

C:\xampp\htdocs56

Step 2 — Add to Hosts File

Edit:

C:\Windows\System32\drivers\etc\hosts

Add:

127.0.0.1   localhost56

Step 3 — Add Virtual Host Config

Add this to httpd-xampp.conf:

<VirtualHost localhost56:80>
    DocumentRoot "C:\xampp\htdocs56"
    ServerName localhost56

    <Directory "C:\xampp\htdocs56">
        Require all granted    
    </Directory>

    <FilesMatch "\.php$">
        SetHandler application/x-httpd-php56-cgi
    </FilesMatch>
</VirtualHost>

Now:

  • http://localhost → Default PHP
  • http://localhost56 → PHP 5.6

🔄 Final Step — Restart Apache

  1. Save all configuration files
  2. Restart Apache from XAMPP Control Panel

🎯 Summary

Method Best For
Directory-based Running only specific legacy projects
Separate Port Testing same project in multiple PHP versions
Virtual Host Clean environment separation

✔️ You now have multiple PHP versions running under one XAMPP installation.


Source

Based on this StackOverflow answer:

https://stackoverflow.com/a/49586592/7906006

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment