XAMPP and Different PHP Versions
This is not a question! I recently had been trying to get XAMPP as my local host to use different versions of PHP for testing. While it was not easy to get the information, I finally got it to work. I found all kinds of different instructions all over the net. Some use virtual servers and that is an option. This seemed to be the best for my needs. Some input from the Apache forum was critical to get this to work. I guess I was being annoying as they wanted me to go learn all about servers and server configurations! I am not a server guy and all I can show you is what I have working. PLEASE do not ask me to explain what is in the files. I have read through some of the documentation but I am still sort of lost. I am sure that there are some folks here on the forum that can explain this better. I am also trying to get Xdebug to work with all three versions as well. That is a work in progress. If you are interested, please keep reading.
First off, install the version of XAMPP you want to use as a base install. I have 7.4.25 as my installed base to xampp\
Next under you XAMPP create two new folders, in my case xampp/php8 (8.0.10 is the actual one) and xampp/php81v (8.1.1 is the actual version). Your base install version (7.4.25 for me) will be under xampp\php). Go to php.net and download the Windows version of that PHP file. Make sure you get the regular zip file as I cannot vouch for the others. I was told that the "debug" version was not the correct one. Unzip the PHP versions into the correct folder.
Under the XAMPP control panel, open httd-xampp.config file and add the following to the bottom of the file. Note how the versions are shown. you need to make four changes for each version as yours may be different. I went forward but I am told that you can go backwards to older versions if needed.
Code:
ScriptAlias /php8-cgi/ "C:/xampp/php8/"
<Directory "C:/xampp/php8">
SetEnv PHPRC "C:/xampp/php8"
AllowOverride None
Options None
Require all denied
<Files "php-cgi.exe">
Require all granted
</Files>
</Directory>
ScriptAlias /php81-cgi/ "C:/xampp/php81/"
<Directory "C:/xampp/php81">
SetEnv PHPRC "C:/xampp/php81"
AllowOverride None
Options None
Require all denied
<Files "php-cgi.exe">
Require all granted
</Files>
</Directory>
create a new .htaccess file for each version. The trick is to set the php version by using the .htaccess so you copy the correct .htaccess file to the store folder where you want to use the PHP version. I actually made two different files and named them PHP8htaccess and PHP81htaccess. All I have to do to change PHP versions is to rename either file to .htaccess.
for PHP 8.0.1, I used
Code:
<FilesMatch "\.php$">
SetHandler application/x-httpd-php-cgi
</FilesMatch>
<IfModule actions_module>
Action application/x-httpd-php-cgi "/php8-cgi/php-cgi.exe"
</IfModule>
and for 8.1.1, I used
Code:
<FilesMatch "\.php$">
SetHandler application/x-httpd-php-cgi
</FilesMatch>
<IfModule actions_module>
Action application/x-httpd-php-cgi "/php81-cgi/php-cgi.exe"
</IfModule>
Re: XAMPP and Different PHP Versions
I appreciate the effort/time involved and altruistic motives for your post. Multiple times I have considered doing the same, but didn't.
This sort of information is invaluable and liable to changes/be tweaked so maybe you would consider putting it on Github so others may be tempted to add their particular experiences/problems/solutions.
Personally I have moved from Xampp to Laragon in which it is so easy to add other versions (Apache, mysql, maria, php) that if you have a look at it you may get a bit angry at how much time you have spent on Xampp, but you have learnt a lot!
Re: XAMPP and Different PHP Versions
where would I put this on Github? I am still a newb.....
Teach me Obi-wan! :D
Re: XAMPP and Different PHP Versions
Mine just work fine by installing them in:
xampp_7_4
and
xampp_8_0
A shortcut for each on the desktop screen and so far so good.
Re: XAMPP and Different PHP Versions
Quote:
Originally Posted by
Philibel
Mine just work fine by installing them in:
xampp_7_4
and
xampp_8_0
A shortcut for each on the desktop screen and so far so good.
but then you need separate htdocs folders. Xdebug will not work like this, at least from my experience. I can change PHP versions on the fly without even restarting Apache.
Re: XAMPP and Different PHP Versions
Quote:
where would I put this on Github? I am still a newb.....
Create an account on GitHub, get Gitkraken, watch all their video tutorials and make/play with a test repository.
Re: XAMPP and Different PHP Versions
FWIW, I've been using the port-based solution identified in this (https://stackoverflow.com/questions/...sions-in-xampp) stackoverflow posting.
That way, I can access a site that 'needs' PHP 5.6 on localhost:8056/something and can run the zc157c upgrade of that site on localhost:8080/something.
Re: XAMPP and Different PHP Versions
Quote:
Originally Posted by
lat9
FWIW, I've been using the port-based solution identified in this (
https://stackoverflow.com/questions/...sions-in-xampp) stackoverflow posting.
That way, I can access a site that 'needs' PHP 5.6 on localhost:80
56/something and can run the zc157c upgrade of that site on localhost:80
80/something.
I saw that one and I think it is a perfect answer as well. I did not know if the port settings would cause problems with Netbeans & Xdebug. I do not have an answer for this so I chose a path! There may not be any problem at all.
Your solution could get memorized in the browsers, right? I sort of WANTED to make a larger effort to make sure I was on the right version. I would end up thinking I was on 7.4 and actually be on 8.0. Again, my fears may be overstated.
Re: XAMPP and Different PHP Versions
Quote:
Originally Posted by
g2ktcf
Your solution could get memorized in the browsers, right?
Perhaps use for each php-version a different browser? Chrome, Edge, Firefox or Opera to separate the cache memories.
Re: XAMPP and Different PHP Versions
Quote:
Originally Posted by
Philibel
Perhaps use for each php-version a different browser? Chrome, Edge, Firefox or Opera to separate the cache memories.
you still need to check dev code on all browsers for compatibility, wouldn't you? I like my chosen method because I know, I must "select" a version each time I test something...AND I am testing the same code each time. There are other ways to do this as lat9 mentioned. So ymmv.
Re: XAMPP and Different PHP Versions
Quote:
Originally Posted by
g2ktcf
where would I put this on Github? I am still a newb.....
You can use Gists for this kind of thing.
https://gist.github.com/
Re: XAMPP and Different PHP Versions
Quote:
Originally Posted by
lat9
FWIW, I've been using the port-based solution identified in this (
https://stackoverflow.com/questions/...sions-in-xampp) stackoverflow posting.
That way, I can access a site that 'needs' PHP 5.6 on localhost:80
56/something and can run the zc157c upgrade of that site on localhost:80
80/something.
I tried this method out on my main desktop computer. It worked right off the bat when setup as per https://themanish.com/run-multiple-v...ultiple-xampp/
This may be different that what you did above. However, after I added Xdebug, EVERYTHING broke lol. I kept getting "server configuration" errors. So the first thing I did was compare the three different php.ini files. I used the one from the base Xampp install as the go by. I used Winmerge to get them aligned. Everywhere I saw a directory with /php, I updated that ini file to /php8 or /php81 as needed. Did not change a thing! lol
So, I started looking into the server logs and found out that I put the xdebug.dll in the wrong folder. There were numerous errors in the log of not being able to open that file. Also, there was another error regarding "browsecap.ini" not being available. The base install php/extras folder has was more items in it than the versions downloaded directly from php.net. So I just copied the browsecap.ini file into the new php directories and then everything seemed to work fine. I do not know what problems we will have with the other missing items from this php/extras folder but at least I can get phpinfo to work in all three versions with Xdebug 3.1.2 installed!
Next step is to see if I can get Netbeans connected to all three...:D
Re: XAMPP and Different PHP Versions
Re: XAMPP and Different PHP Versions
Thank you for sharing your experience and solution with using different versions of PHP in XAMPP. It can be helpful for those who face a similar problem.
For those who are not familiar with XAMPP, it is a free and open-source cross-platform web server solution stack package developed by Apache Friends, consisting mainly of the Apache HTTP Server, MariaDB database, and interpreters for scripting languages, including PHP.
Your solution involves creating separate folders for each version of PHP and configuring XAMPP to use them via the httd-xampp.config file and .htaccess files. The ScriptAlias directive is used to define an alias to the PHP-CGI executable, which can be used to execute PHP scripts. The <Files> directive is used to specify which files are affected by the directives within the block. The SetHandler directive is used to set the handler for the specified file extension. The Action directive associates a script or program with a particular MIME type.
I hope your solution works well for you, and good luck with getting Xdebug to work with all three versions. If you have any further questions or concerns, please don't hesitate to ask.