16

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.

Isaac Bennetch
  • 11,830
  • 2
  • 32
  • 43
Hope
  • 644
  • 2
  • 6
  • 21
  • If you look close there wont be a big list of things to fix. Might as well upgrade the code rather than to downgrade the language – Hanky Panky Jan 13 '16 at 02:01
  • @Hanky웃Panky I have a large file in my old xampp it would take a very long time to update all those codes. What i am thinking is to use two php version or two xampp version the problem is I don't know how. – Hope Jan 13 '16 at 02:05
  • 2
    http://stackoverflow.com/a/24000550/1570534 – Hanky Panky Jan 13 '16 at 02:30
  • @Hanky웃Panky I think this will be a good remedy. thank you so much. I will try to install two xampp now. – Hope Jan 13 '16 at 02:44

1 Answers1

30

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

Lorenzo Magon
  • 544
  • 5
  • 17
  • 2
    This worked very well for my purposes. If xampp fails to load please check the `C:\xampp\apache\conf\extra\httpd-xampp` file remember php modules are based on the version so it should have statements like php5_module or php7_module depending on the version. For some reason when I switched to php7 the httpd-xampp still had declarations for php5. Thank you very much @Lorenzo! – greaterKing Oct 14 '17 at 21:23
  • Today I updated my Xampp installation to PHP 7.3.0 and I managed to keep previous versions of PHP using the method mentioned in my answer, so I confirm that it continues to work fine. – Lorenzo Magon Dec 29 '18 at 15:56
  • 1
    Thanks Lorenzo. So far, seems working like a charm. I applied your technique with the 64-bit version of xampp. One thing to mention is that for php 7.0.x, xampp for Windows is only available in the 32-bit version. – OuzoPower Oct 22 '19 at 19:02
  • 1
    worked for me - but i got caught out by the fact my original xampp was 32-bit, so following the steps above got me the 64-bit version of php 7.x. After spotting this i replaced php 7 folder with a x86 thread safe version from https://windows.php.net/downloads/releases/archives/ – Mathew Feb 05 '20 at 17:28
  • 1
    This workaround works like charm however file names seems to have changed on some Xampp portable versions. Moreover, if you need (as I did) to change the main Apache port to 8080 on your local machine, you'll need to change them manually on c:/xampp/apache/conf/httpd.conf Thanks @LorenzoMagon for your solution ... saved my day ! – nonap2k Feb 29 '20 at 12:31
  • For me it doesn't work, I guess the php version is associated to a 32- or 64 bit version of xampp. So if I install xampp 64-bit with php 7.4, I can only switch to php versions belonging to a 64-bit xampp version. Therefore I can't switch to php 5.6 since it is only available as 32-bit xampp (that's my hypothesis). I get "Error: Apache shutdown unexpectedly.". – Galivan Mar 29 '20 at 14:42
  • @Galivan: I have checked my version of XAMPP, it is the 7.3.0 64-bit version and it is working without problems, unfortunately I have not yet tried version 7.4.0, I hope to be able to test it in the next few days ... the error you receive from Apache, however, suggests that there is some configuration problem with the vhosts.conf file: check that there are instructions that are not compatible with php 5.6 – Lorenzo Magon Mar 31 '20 at 08:41
  • @Galivan: in my previous comment unfortunately I made a mistake in checking the php version, in fact I had version 7.3 32bit and not 64bit! therefore the problem you encountered was correct: my solution does not work with hybrid versions of xampp... – Lorenzo Magon Feb 12 '22 at 17:20
  • Today I updated my Xampp installation to 64-bit versions following my same previous method: I managed to get PHP versions 7.3.33, 7.4.27, 8.0.11 and 8.1.2 to work, I started from the Xampp installation 8.1.2 in order to have the latest version of the Control Panel (3.3.0) and obtaining the other versions of PHP from the "portable version" packages. As for the MySQL databases I simply kept the files in the `C:/xampp/mysql/data/` folder from the old to the new installation. I therefore confirm that my procedure continues to work correctly. – Lorenzo Magon Feb 12 '22 at 17:27