Introduction
Running multiple PHP versions (e.g., 8.1 to 8.4) side-by-side on IIS 10 allows web admins to host different applications requiring specific PHP versions. This is ideal for development, testing, or hosting multiple client sites with varying compatibility requirements.
This guide covers a complete, verified setup using FastCGI on Windows Server editions with IIS 10. Each PHP version will run in isolation and be assigned to different websites or virtual directories.
Step 1: Prerequisites
- IIS 10 installed with CGI feature enabled (Windows Features > Internet Information Services > Application Development Features > CGI).
- Administrator rights on the system.
- Latest Microsoft Visual C++ Redistributable (2015–2022 x64) installed.
⚠️ Only use Non-Thread Safe (NTS) PHP builds for FastCGI on IIS.
Step 2: Download PHP Versions (8.1 to 8.4)
Visit: https://windows.php.net/download/
Download the following x64 NTS ZIP packages:
php-8.1.x-nts-Win32-vs16-x64.zip
php-8.2.x-nts-Win32-vs16-x64.zip
php-8.3.x-nts-Win32-vs16-x64.zip
php-8.4.x-nts-Win32-vs17-x64.zip
Step 3: Extract and Prepare PHP Versions
- Create folder structure:
C:\PHP\php-8.1\
C:\PHP\php-8.2\
C:\PHP\php-8.3\
C:\PHP\php-8.4\
- Extract each ZIP package into its respective folder.
- Each folder should now contain:
php-cgi.exe
php.exe
ext\
folderphp.ini-development
andphp.ini-production
Step 4: Configure php.ini Files
For each version:
- Rename
php.ini-production
tophp.ini
. - Edit
php.ini
with the following key settings:
extension_dir = "ext"
session.save_path = "C:\\Windows\\Temp"
expose_php = Off
fastcgi.impersonate = 1
cgi.fix_pathinfo = 1
cgi.force_redirect = 0
date.timezone = Asia/Kolkata
memory_limit = 256M
upload_max_filesize = 50M
post_max_size = 50M
max_execution_time = 60
max_input_time = 90
disable_functions = exec,passthru,shell_exec,system,proc_open,popen,curl_exec
- Enable required extensions:
extension=mysqli
extension=pdo_mysql
extension=gd
extension=openssl
- (Optional) Configure error logging:
log_errors = On
error_log = "C:\\php-errors\\php8x.log"
- (Recommended) Enable and separate Opcache:
opcache.enable=1
opcache.validate_timestamps=1
opcache.revalidate_freq=60
opcache.memory_consumption=128
opcache.file_cache="C:\\php-opcache\\php8x"
🔁 Repeat this for all four versions.
Step 5: Add PHP Versions to IIS FastCGI
- Open IIS Manager > Select your server > Open FastCGI Settings.
- Click Add Application for each version:
C:\PHP\php-8.1\php-cgi.exe
C:\PHP\php-8.2\php-cgi.exe
C:\PHP\php-8.3\php-cgi.exe
C:\PHP\php-8.4\php-cgi.exe
- For each entry:
- Click Edit > Add environment variable:
- Name:
PHPRC
- Value:
C:\PHP\php-8.x\
- Name:
- Click Edit > Add environment variable:
- (Optional but recommended):
PHP_FCGI_MAX_REQUESTS = 1000
This defines how many requests a FastCGI child process will serve before recycling. Useful to mitigate memory leaks.
Step 6: Configure Handler Mappings per Website
Method A: Central Registration with Per-Site Selection
- IIS Manager > Server Node > Handler Mappings > Add Module Mapping:
- Request path:
*.php
- Module:
FastCgiModule
- Executable:
C:\PHP\php-8.x\php-cgi.exe
- Name:
PHP 8.x via FastCGI
- Request path:
- Repeat for each PHP version.
- For each site:
- Go to site > Handler Mappings > Remove other PHP handlers.
- Or use View Ordered List > Move desired handler to top.
🔄 Handler order determines which PHP version runs when multiple handlers exist for the same path.
Method B: Site-Specific Mapping
- Select Site > Handler Mappings > Add Module Mapping:
- Use only the correct version’s
php-cgi.exe
.
- Use only the correct version’s
Virtual Directory Use:
- You can assign different PHP versions to subfolders by converting them into Applications and applying a handler mapping locally. Each subfolder can run a different PHP version if needed.
Step 7: Test Setup
- Create
phpinfo.php
in the root of each site:
<?php phpinfo(); ?>
- Open in browser:
http://yoursite/phpinfo.php
- Confirm:
- PHP version at top
Loaded Configuration File
- Correct extensions enabled
- Opcache path (if configured)
- Test via CLI (optional):
C:\PHP\php-8.1\php-cgi.exe -v
If it outputs the correct version, the binary is working correctly.
Step 8: Tips and Caveats
- ⚠️ Never share
ext\
folders between versions. - ⚠️ Do NOT add PHP folders to
PATH
if unnecessary. - ✅ Avoid setting global
PHPRC
orPHPIniDir
system-wide. - ✅ Use different error logs per version.
- ✅ Recycle FastCGI apps from FastCGI Settings after any
php.ini
changes. - ✅ Use separate Opcache file cache directories for each PHP version.
- ⚠️ Watch for session sharing if
session.save_path
is the same across versions. - ✅ Use dedicated IIS App Pools per site if performance tuning is needed.
Step 9: Optional – PHP Manager for IIS
PHP Manager for IIS provides a GUI to manage multiple PHP installations. It simplifies handler mapping, php.ini changes, and FastCGI registration. Useful for rapid switching and verification.
Final Notes
You now have a robust, production-ready setup for running PHP 8.1, 8.2, 8.3, and 8.4 concurrently on IIS 10. Each site or virtual directory can independently use the PHP version it needs, ensuring complete compatibility with legacy and modern apps alike.
✅ Share this with your team or IT forum to help others implement flexible, versioned PHP hosting environments on Windows IIS.