How to Run Multiple PHP Versions on the Same Apache Server on Windows
A step-by-step guide for Apache 2.4 on Windows
For software developers who maintain both older applications and more modern projects, the ability to run multiple PHP versions concurrently on the same Apache server is a frequent request. This post walks you through how you can store multiple PHP versions with Apache on Windows using mod_fcgid and what the benefits are in comparison to mod_php.
Why Use Multiple PHP Versions?
It’s quite common for applications to rely on various PHP versions because of legacy applications or new functionality exclusive to modern ones. Rather than keeping multiple machines, or containers, you can have your local Apache server serve various PHP versions, based on the domain, or virtual host.
Understanding mod_php
vs mod_fcgid
What is mod_php
(php_module
)?
mod_php
(or php_module
) is the old way of running PHP directly inside the Apache process. This method loads a specific version of PHP via the Apache LoadModule
directive. It's fast and easy to configure for single PHP version setups:
LoadModule phpX_module "path/to/phpX.Y/phpXapache2_4.dll"
AddHandler application/x-httpd-php .php
However, this approach comes with significant limitations:
- You can only load one PHP version per Apache instance.
- Switching PHP versions means restarting Apache with a new configuration.
- Not ideal for systems with multiple apps needing different PHP versions.
What is mod_fcgid
?
mod_fcgid
is an Apache module that implements the FastCGI protocol. It allows Apache to communicate with an external PHP interpreter (php-cgi.exe
). This approach is highly flexible and supports running multiple PHP versions at the same time, which means:
- Multiple PHP versions can run simultaneously.
- Each app or VirtualHost can specify its own PHP version.
- PHP runs as an external process, offering better isolation.
In short, mod_fcgid
allows you to delegate PHP execution to whichever php-cgi.exe
you want — giving each virtual host its own independent PHP runtime.
Apache Directory Structure
Let’s assume the following setup:
- Apache:
C:/apache
- PHP 5.4:
C:/php/5.4.x/
- PHP 8.4:
C:/php/8.4.x/
- Websites:
New App:
-C:/app/new
Legacy App:
-C:/app/legacy
Step-by-Step Guide: Running Multiple PHP Versions Side by Side
Apache on Windows doesn’t include mod_fcgid
by default, so the first step is to download, install, and configure it correctly:
Step 1
Visit Apache Lounge and download the version of mod_fcgid
that matches your Apache version (e.g., 2.4.x) and architecture (Win32/Win64).
Step 2: Add the mod_fcgid
Module
Extract the mod_fcgid
archive and copy the mod_fcgid.so
file into your Apache modules directory: C:\apache\modules\mod_fcgid.so
.
Step 3: Enable mod_fcgid
in Apache
Open your httpd.conf
file and add the following line to load the module:
LoadModule fcgid_module modules/mod_fcgid.so
Step 4: Remove Legacy mod_php
Configuration
In httpd.conf
, remove or comment out any lines related to php5_module
and PHPIniDir
, such as:
## PHP handler configuration
# LoadModule php5_module "C:/php/5.4.30/php5apache2_4.dll"
## Configure the PHP file location
# PHPIniDir "C:/php/5.4.30"
## Any file ending in .php is passed to the application/x-httpd-php handler
## This is used when PHP is loaded as an Apache module usually for php5_module
# AddHandler application/x-httpd-php .php
## Forces a specific handler for all files matching a given pattern
## Overrides AddHandler
# <FilesMatch \.php$>
# SetHandler application/x-httpd-php
# </FilesMatch>
# <Directory />
# AllowOverride none
# Require all granted
# </Directory>
# <Directory "c:/app/legacy">
# Options Indexes FollowSymLinks
# AllowOverride All
# Require all granted
# </Directory>
# DocumentRoot "c:/app/legacy"
# ErrorLog "logs/error.log"
Step 5: Create php54.conf
for PHP 5.4 (CGI Handler)
In C:/apache/conf/extra/
, create a file named php54.conf
with the following contents:
<IfModule fcgid_module>
FcgidInitialEnv PHPRC "C:/php/5.4.x"
FcgidInitialEnv PATH "C:/php/5.4.x"
FcgidWrapper "C:/php/5.4.x/php-cgi.exe" .php
</IfModule>
Step 6: Create php84.conf
for PHP 8.4
Similarly, create php84.conf
in the same directory:
<IfModule fcgid_module>
FcgidInitialEnv PHPRC "C:/php/8.4.x"
FcgidInitialEnv PATH "C:/php/8.4.x"
FcgidWrapper "C:/php/8.4.x/php-cgi.exe" .php
</IfModule>
Step 7: Configure Virtual Hosts
Edit httpd-vhosts.conf
(usually located at C:/apache/conf/extra/httpd-vhosts.conf
) and add the following:
# Legacy PHP 5.4 Application
<VirtualHost *:80>
DocumentRoot "C:/app/legacy"
ServerName legacy-app.local
ServerAlias legacy-app.local
<Directory "C:/app/legacy">
Options +ExecCGI
AllowOverride All
Require all granted
</Directory>
Include conf/extra/php54.conf
ErrorLog "logs/legacy-app.local-error.log"
CustomLog "logs/legacy-app.local-access.log" common
</VirtualHost>
# New Framework based App PHP 8.4
<VirtualHost *:80>
DocumentRoot "C:/app/new"
ServerName new-app.local
ServerAlias new-app.local
<Directory "C:/app/new">
Options +ExecCGI
AllowOverride All
Require all granted
</Directory>
Include conf/extra/php84.conf
ErrorLog "logs/new-app.local-error.log"
CustomLog "logs/new-app.local-access.log" common
</VirtualHost>
Step 8: Register the Virtual Hosts
In your httpd.conf
, include the virtual host file:
Include conf/extra/httpd-vhosts.conf
Also, add the following directive to associate .php
files with FastCGI:
<FilesMatch \.php$>
SetHandler fcgid-script
</FilesMatch>
Step 9: Update Your Hosts File
Edit your hosts
file located at C:\Windows\System32\drivers\etc\hosts
and add:
127.0.0.1 legacy-app.local
127.0.0.1 new-app.local
Final Step: Test the Setup
Restart Apache using:
httpd.exe -k restart -n "server_apache"
Then, place a phpinfo.php
test file in both C:/app/legacy
and C:/app/new
:
<?php phpinfo(); ?>
Open the following URLs in your browser to verify each PHP version is running correctly:
- http://legacy-app.local/phpinfo.php → should show PHP 5.4
- http://new-app.local/phpinfo.php → should show PHP 8.4
Conclusion
Using mod_fcgid
, you can run as many PHP versions as needed on the same Apache instance. This flexibility allows you to maintain legacy systems while building new services using the latest tools. Always isolate configurations per VirtualHost, and remember that mod_php
is no longer the best solution when multiple PHP versions are involved.