Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

php

version

xampp

I made a backup file for my php projects then uninstall the old xampp(php 5.x.x). After that, I try to install the latest xampp version(php 7.0.1) and put the backup file from my old xampp to run into the new one including its database. The problem is that, when I try to run my old file I encounter lot of errors. It seems there are lots of code that are obsolete to the new php version. What is the best way to run my old file again ? I think I might reinstall the old xampp but I also want to use the latest php version. What is the ideal thing to do ? I have read some article about it, but I didn't found a clear explanation about this. Please help.

like image 893
Hope Avatar asked Jan 13 '16 01:01

Hope


People also ask

Can you run multiple versions of PHP at the same time?

Together, you can use Apache and PHP-FPM to host multiple PHP web-applications, each using a different version of PHP, all on the same server, and all at the same time.


1 Answers

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).

like image 185
Lorenzo Magon Avatar answered Sep 21 '22 13:09

Lorenzo Magon