Running php 5.x and php 7.0 at the same time in my windows [duplicate]

做~自己de王妃 提交于 2019-11-29 22:33:10

I found a solution to quickly change the version of PHP from 5.6, 7.0 and 7.1 with only one Xampp installation.

I'm currently using it to develop locally with Windows without having problems, the database remains unchanged and also the Apache httpd-vhosts.conf configuration file: this allows the PHP version to be changed quickly and easily.

From the official ApacheFriends website download the latest 3 versions of Xampp (Control Panel 3.2.2) for windows portable version:

xampp-portable-win32-7.1.7-0-VC14.zip
xampp-portable-win32-7.0.21-0-VC14.zip
xampp-portable-win32-5.6.31-0-VC11.zip

Unzip the Xampp win32-7.1.7 version in C:\ 
Rename the C:\xampp\php folder to C:\xampp\php-7.1.7

From Xampp win32-7.0.21 version
extract the \xampp\php folder to C:\xampp\php
and then rename it to C:\xampp\php-7.0.21

From Xampp win32-5.6.31 version
extract the \xampp\php folder to C:\xampp\php
and then rename it to C:\xampp\php-5.6.31

Go to C:\xampp\apache\conf\extra
and rename the httpd-xampp.conf file in httpd-xampp-php-7.conf

From Xampp win32-5.6.31 version extract the \xampp\apache\conf\extra\httpd-xampp.conf file to C:\xampp\apache\conf\extra\httpd-xampp.conf
and then rename it to httpd-xampp-php-5.conf

In C:\xampp** create a new folder with name "**php-switch" and create 3 .bat files, one for each PHP version that you want to manage.

Here is the code to include in the individual files:

set-php-5.6.bat

@echo off
rmdir C:\xampp\php
mklink /J C:\xampp\php C:\xampp\php-5.6.31
del C:\xampp\apache\conf\extra\httpd-xampp.conf
copy C:\xampp\apache\conf\extra\httpd-xampp-php-5.conf C:\xampp\apache\conf\extra\httpd-xampp.conf 
echo The version of PHP 5.6.31 is set
pause

set-php-7.0.bat

@echo off
rmdir C:\xampp\php
mklink /J C:\xampp\php C:\xampp\php-7.0.21
del C:\xampp\apache\conf\extra\httpd-xampp.conf
copy C:\xampp\apache\conf\extra\httpd-xampp-php-7.conf C:\xampp\apache\conf\extra\httpd-xampp.conf
echo The version of PHP 7.0.21 is set
pause

set-php-7.1.bat

@echo off
rmdir C:\xampp\php
mklink /J C:\xampp\php C:\xampp\php-7.1.7
del C:\xampp\apache\conf\extra\httpd-xampp.conf
copy C:\xampp\apache\conf\extra\httpd-xampp-php-7.conf C:\xampp\apache\conf\extra\httpd-xampp.conf
echo The version of PHP 7.1.7 is set
pause

Well, it's time to test if everything works:
- run the .bat file for the PHP version you want to set (eg set-php-7.1.bat)
- start Xampp Control Panel and start Apache
- check the PHP live version locally by going to the http://localhost/dashboard/phpinfo.php page

To change PHP version:
- from Xampp Control Panel stop Apache
- run .bat files to change PHP version (eg set-php-5.6.bat)
- from Xampp Control Panel start Apache
- check the PHP live version locally by going to the http://localhost/dashboard/phpinfo.php page

Considerations:

Compared to installing multiple versions of Xampp in separate folders, this solution allows to have only one Xampp Control Panel and only change the PHP version while keeping the batabase and any Apache customizations in the C:\xampp\apache\conf\extra\httpd-vhosts.conf file unchanged.

Also, this solution can work with Linux and Mac by simply changing the .bat files (and their commands) to .sh for Linux and .command for Mac files (I personally did not run tests on Linux and Mac, but I expect it to be done without any problems).

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!