Skip to content

Instantly share code, notes, and snippets.

@quangpd
Created April 23, 2019 07:08
Show Gist options
  • Save quangpd/2211dbac419e7ad941a6c3f938c8fb0d to your computer and use it in GitHub Desktop.
Save quangpd/2211dbac419e7ad941a6c3f938c8fb0d to your computer and use it in GitHub Desktop.
Setup xampp multi PHP version
1. Install XAMPP with the PHP Version you want to run mainly, e.g. PHP 7.2 => resides by default in Installpath\xampp\php
2. Copy other php Versions in Installpath\xampp\, eg PHP 5.4 in => Installpath\xampp\php5
If you are lazy like me, just grab the other php folder from old xampp installations, => beneficial since the used dlls are already in the right place
3 Make sure every php version on her own has a working php.ini.
use individual error logs per version:
error_log="D:\xampp\php5\logs\php_error_log"
error_log="D:\xampp\php\logs\php_error_log"
point to the correct extensions folder:
; Directory in which the loadable extensions (modules) reside.
; http://php.net/extension-dir
; extension_dir = "./"
; On windows:
extension_dir="D:\xampp\php5\ext"
; Directory in which the loadable extensions (modules) reside.
; http://php.net/extension-dir
; extension_dir = "./"
; On windows:
extension_dir="D:\xampp\php\ext"
3. edit the following files
apache\conf\httpd.conf
add codelines at the bottom of the file, the phpvhosts.conf will house our custom config
##custom
Include conf/extra/phpvhosts.conf
apache\conf\extra\httpd-xampp.conf
find and comment the loading lines for the php module: depending on your php version
# PHP-Module setup
#
#LoadFile "D:/xampp/php/php7ts.dll"
#LoadFile "D:/xampp/php/libpq.dll"
#LoadModule php7_module "D:/xampp/php/php7apache2_4.dll"
apache\conf\extra\phpvhosts.conf
create this file with following content
# Port-based virtual hosting: every php install uses a vhost on a different port, the main php version will listen to port 80 (defined in httpd.conf)
# Port are 84xx with xx for php version
Listen 8472
Listen 8454
### BASE virtualhost
### set up the main php version we're using, loading the main php version as module
<VirtualHost *:80>
LoadFile "D:/xampp/php/php7ts.dll"
LoadFile "D:/xampp/php/libpq.dll"
LoadModule php7_module "D:/xampp/php/php7apache2_4.dll"
PHPINIDir "D:/xampp/php"
php_value extension_dir "D:/xampp/php/ext/"
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .php
</VirtualHost>
### call php 7.2 via port
<VirtualHost *:8472>
</VirtualHost>
### call php 5.4 via port && cgi
<VirtualHost *:8454>
SetEnv PHPRC "D:/xampp/php5/"
ScriptAlias /php-cgi/ "D:/xampp/php5/"
<Directory "D:/xampp/php5">
AllowOverride None
Options None
Require all denied
<Files "php-cgi.exe">
Require all granted
</Files>
</Directory>
<Directory "D:/xampp/cgi-bin">
<FilesMatch "\.php$">
SetHandler cgi-script
</FilesMatch>
<FilesMatch "\.phps$">
SetHandler None
</FilesMatch>
</Directory>
<FilesMatch "\.php$">
SetHandler application/x-httpd-php-cgi
</FilesMatch>
<IfModule actions_module>
Action application/x-httpd-php-cgi "/php-cgi/php-cgi.exe"
</IfModule>
</VirtualHost>
4. restart your XAMPP Server
our server listens now on different ports and uses the respective php version but serves from always the same htdocs folder
maybe run a small phpinfo() on different ports to check if everything is working as intended
localhost => php7
localhost:8474 => php7
localhost:8454 => php5
if you want to add more php versions, add them in the phpvhosts.conf file with an additional port
References:
GGGeek Tutorial
StackOverflow
5. Bonus:
If you want to access your different php installations not only via hostname:Port you can also set up some named virtual hosts
5.1 add the host names to your hosts file.
C:\Windows\System32\drivers\etc\hosts
add the following lines for new localhost names
127.0.0.1 php5.localhost
127.0.0.1 php7.localhost
5.2 edit the phpvhosts.conf file to tell apache what to do when the given hostname is called
add the Name VirtualHost:
Listen 8472
NameVirtualHost *:8472
Listen 8454
NameVirtualHost *:8454
In each Virtualhost tag add the name of the vhost with port 80
inside tag add the ServerName attribute
for php7
<VirtualHost *:8472 php7.localhost:80>
ServerName php7.localhost
</VirtualHost>
for php5
<VirtualHost *:8454 php5.localhost:80>
ServerName php5.localhost
[...]
</VirtualHost>
5.3 Restart your xampp.
You can now call the pages in your htdocs folder with php5 or php7
localhost => php7
localhost:8474 => php7
php7.localhost => php7
localhost:8454 => php5
php5.localhost => php5
@HariharanUmapathi
Copy link

[browscap]
; http://php.net/browscap
browscap="D:\xampp\php\extras\browscap.ini"

is also needed on cofiguring php with cgi
if not modified the path it shows bad header error with php-cgi

@kiranrs
Copy link

kiranrs commented Aug 11, 2023

You know a very very easy way (for Windows Users)?

  1. Backup your files and DB from XAMPP
  2. Uninstall XAMPP
  3. Download and install WAMP
  4. Enjoy Multiple versions of PHP even with FCGI !!!

@HariharanUmapathi
Copy link

HariharanUmapathi commented Aug 27, 2023 via email

@MirroringCode
Copy link

can this also apply for linux systems, in my case I have xampp on ubuntu 20

@HariharanUmapathi
Copy link

can this also apply for linux systems, in my case I have xampp on ubuntu 20

Yeah! Make sure you have backup before changing anything!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment