📜 ⬆️ ⬇️

Several versions of PHP on a Windows machine

A very urgent task: To be able to click on the mouse to change the version of PHP on a Windows machine. Earlier 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 with 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 

In the file C: \ a \ apache \ conf \ httpd.conf after all LoadModule.
')
Create a symbolic link php.conf <===> php5.conf

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

Download the necessary versions of PHP ...


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

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

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

Now we 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 /dc:\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 /dc:\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'niki, and specify in the properties of each "Run as administrator".

Thanks for attention!

UPD:

At the prompt, gewisser did a little differently:

In the folder C: \ a \ apache \ conf 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 something else that millions will use, it is just the answer to the post as the most convenient option.

Many are familiar with numerous WAMP-kits, however, judging by the fact that there are not few such articles, it can be concluded that not everyone wants to use them.

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

Thank!

Source: https://habr.com/ru/post/312316/


All Articles