Run multiple PHP versions under Apache 2.4

It is possible to run multiple PHP versions under Apache as Apache's module.

I had tried to implement Apache's logic to include the PHP extension files. Below are the steps to run PHP5 and PHP7 modules under Apache 2.4 in Windows operating system.

Things to remember:
- Two separate apache services will be installed.

1) Uninstall your current apache service.
httpd.exe -k uninstall -n <YOUR APACHE SERVICE NAME>

2) Open up your httpd.conf file and comment Listen 80 and ServerName localhost:80 directives.

3) Comment the lines which are related to inclusion of PHP module. In my httpd.conf file below lines were commented.
#LoadModule php5_module "D:/*/php/php5apache2_4.dll"
#AddType application/x-httpd-php .php
#PHPIniDir "D:/*/php"



4) Create a separate conf file namely httpd_php7.conf under apache2/conf directory. And, put below content in it. Do not forget to change it with your specific paths and values.
Include conf/httpd.conf
Listen 80
ServerName localhost:80
LoadModule php7_module "D:/*/php7/php7apache2_4.dll"
AddHandler application/x-httpd-php .php
PHPIniDir "D:/*/php7/"


5) Install apache service by configuring the above created conf file as main configuration.
httpd.exe -k install -n "apachePHP7" -f "D:/*/*/conf/httpd_php7.conf"

6) Repeat the steps 4 and 5 by replacing all "7" by "5". Make sure to provide some different name for the apache service. For example, httpd.exe -k install -n "apachePHP5" -f "D:/*/*/conf/httpd_php5.conf"

Now create a phpinfo() file in your document root and fire it in browser by enabling the recently created services one by one.
If everything went well, it will show different PHP versions in your browser depending on the running apache service.

You can further expand the configuration to run different PHP versions for different virtual hosts.