Several versions of PHP on a Windows machine

Very urgent task: To be able to change the version of PHP on a Windows machine by clicking the mouse. Previously, there was a similar article in which 3 copies of httpd.conf are created. What for? When there is the simplest solution.

Download the archive from Apache HTTPd and unpack it into a folder, for example, C: \ a \ apache. In the folder C: \ a \ apache \ conf, we create two configuration files ...

php5.conf
LoadModule php5_module "c:/a/php/php5apache2_4.dll"
AddHandler application/x-httpd-php .php
PHPIniDir "c:/a/php"

php7.conf
LoadModule php7_module "c:/a/php/php7apache2_4.dll"
AddHandler application/x-httpd-php .php
PHPIniDir "c:/a/php"

... and add the line:

Include conf/php.conf

To the file C: \ a \ apache \ conf \ httpd.conf after all the LoadModule.

Create a symlink php.conf <===> php5.conf

Hidden text
mklink c:\a\apache\conf\php.conf c:\a\apache\conf\php5.conf

Downloading the necessary versions of PHP ...


... and unpack them into the folders C: \ a \ php56 and C: \ a \ php70, respectively.

Earlier, in the Apache configs, we indicated that PHP should be hooked from the C: \ a \ php directory, therefore we create a symbolic link php <===> php56 :

Hidden text
mklink /d c:\a\php c:\a\php56

Now install the service ...

Hidden text
c:\a\apache\bin\httpd -k install -n ApacheHTTPd
c:\a\apache\bin\httpd -k start -n ApacheHTTPd

... and create bat'niki to select the version of PHP:

php56.bat
@echo off
c:\a\apache\bin\httpd -k stop -n ApacheHTTPd
del c:\a\apache\conf\php.conf
rd c:\a\php
mklink /d c:\a\php c:\a\php56
mklink c:\a\apache\conf\php.conf c:\a\apache\conf\php5.conf
c:\a\apache\bin\httpd -k start -n ApacheHTTPd

php70.bat
@echo off
c:\a\apache\bin\httpd -k stop -n ApacheHTTPd
del c:\a\apache\conf\php.conf
rd c:\a\php
mklink /d c:\a\php c:\a\php70
mklink c:\a\apache\conf\php.conf c:\a\apache\conf\php7.conf
c:\a\apache\bin\httpd -k start -n ApacheHTTPd

Now, for convenience, create shortcuts for bat'nikov, and indicate in the properties of each "Run as administrator".

Thanks for attention!

UPD:

At the prompt, gewisser did a little differently:

In the C: \ a \ apache \ conf folder, he created two configuration files:

... for PHP 5.6
LoadModule php5_module "c:/a/php56/php5apache2_4.dll"
AddHandler application/x-httpd-php .php
PHPIniDir "c:/a/php56"
Include "c:/a/apache/conf/httpd.conf"

... for PHP 7.0
LoadModule php7_module "c:/a/php70/php7apache2_4.dll"
AddHandler application/x-httpd-php .php
PHPIniDir "c:/a/php70"
Include "c:/a/apache/conf/httpd.conf"


... and deleted the line from the httpd.conf file
Include conf/php.conf


And changed bat'niki to run:

... for PHP 5.6
@echo off & title Apache HTTPd with PHP 5.6
c:\a\apache\bin\httpd -k stop -n ApacheHTTPd
c:\a\apache\bin\httpd -k uninstall -n ApacheHTTPd
c:\a\apache\bin\httpd -k install -n ApacheHTTPd -f "c:/a/apache/conf/php56.conf"
c:\a\apache\bin\httpd -k start -n ApacheHTTPd

... for PHP 7.0
@echo off & title Apache HTTPd with PHP 7.0
c:\a\apache\bin\httpd -k stop -n ApacheHTTPd
c:\a\apache\bin\httpd -k uninstall -n ApacheHTTPd
c:\a\apache\bin\httpd -k install -n ApacheHTTPd -f "c:/a/apache/conf/php70.conf"
c:\a\apache\bin\httpd -k start -n ApacheHTTPd


PS

This method is not some kind of know-how or anything else that millions will use, this is just an answer to the post as the most convenient option.

Many are familiar with numerous WAMP-kits, however, judging by the fact that there are a lot of similar articles, we can conclude that not everyone wants to use them.

If the society does not mind, write in comments links to similar kits and similar articles, I will attach them to my article.

Thanks!

Also popular now: