I and a lot developer work with multiple project at same time, sometimes we are need working with multiple php version at same time. We don't want to run multiple XAMPP with different ports. So i created this project to help anybody need to run multiple php version at same times with only 1 XAMPP
XAMPP use mod_php to run php, that mean you only work with 1 php version with xampp. To resolve this, i use mod_fcgi
instead mod_php. With mod_fcgi we can redirect request to correctly php version we want.
-
Download XAMPP. this guide use XAMPP 7.2.5 x86
-
Download mod_fcgi .
XAMPP 7.2.5 x86useApache/2.4.33 (Win32), so i will download mod_fcgid-2.3.9-win32-VC15 -
Install XAMPP. for example i installed to
C:/xampp. Extractmod_fcgid-2.3.9-win32-VC15.zipand copy filemod_fcgid.sotoC:/xampp/apache/modules -
Download php version you want from https://windows.php.net/downloads/releases/archives/. Unzip this to folder
C:/xampp. for example i will download php-5.6.35-nts-Win32-VC11-x86 and unzip toC:/xampp/php5635. renamephp5635/php.ini-developmenttophp5635/php.iniand add this line to end ofphp.ini[custom_php_variable] extension_dir = "C:/xampp/php5635/ext/" session.save_path = "C:/xampp/tmp/" upload_tmp_dir = "C:/xampp/tmp/" sys_temp_dir = "C:/xampp/tmp/" soap.wsdl_cache_dir = "C:/xampp/tmp/" -
Copy directory apache to
C:/xampp/apacheand edit fileC:/xampp/apache/conf/php.d/vars.conf# Change this to your xampp on your computer. for this example, it is C:/xampp Define XAMPP_DIR "C:/xampp" # In step #4, i downloaded php 5.6.35, i will add path to here Define PHP_56_CGI "${XAMPP_DIR}/php5635/php-cgi.exe" Define PHP_56_RC "${XAMPP_DIR}/php5635/" # If you download more php versions, just add more lines here, for example php 5.6.30 # Define PHP_5630_CGI "${XAMPP_DIR}/php5630/php-cgi.exe" # Define PHP_5630_RC "${XAMPP_DIR}/php5630/" # The default php version of XAMPP 7.2.5 x86 is php 7.2.5 Define PHP_72_CGI "${XAMPP_DIR}/php/php-cgi.exe" Define PHP_72_RC "${XAMPP_DIR}/php" # This will set default php version when run with xampp Define PHP_CGI ${PHP_72_CGI} Define PHP_RC ${PHP_72_RC} -
Edit file
C:/xampp/apache/conf/extra/httpd-xampp.conf. Comment lines and add more 1 lineInclude "conf/php.d/multi-php-versions.conf"# # PHP-Module setup # #LoadFile "C:/xampp/php/php7ts.dll" #LoadFile "C:/xampp/php/libpq.dll" #LoadModule php7_module "C:/xampp/php/php7apache2_4.dll" #<FilesMatch "\.php$"> # SetHandler application/x-httpd-php #</FilesMatch> #<FilesMatch "\.phps$"> # SetHandler application/x-httpd-php-source #</FilesMatch> # # PHP-CGI setup # #<FilesMatch "\.php$"> # SetHandler application/x-httpd-php-cgi #</FilesMatch> #<IfModule actions_module> # Action application/x-httpd-php-cgi "/php-cgi/php-cgi.exe" #</IfModule> # Load php multiple versions config Include "conf/php.d/multi-php-versions.conf" -
Create your project with vhost: for example i will create project
php-multiple-versionwithphp 5.6andphp 7.2Create vhost fileC:/xampp/apache/conf/vhost/php72-php-multiple-version.local.conf<VirtualHost *:80> ServerAdmin [email protected] DocumentRoot "C:/Projects/php-multiple-version/" ServerName php72-php-multiple-version.local ErrorLog "logs/php72-php-multiple-version.local-error.log" CustomLog "logs/php72-php-multiple-version.local.log" common FcgidInitialEnv PHPRC ${PHP_72_RC} <Directory "C:/Projects/php-multiple-version/"> Define PHP_CGI ${PHP_71_CGI} Include "conf/php.d/php_cgi.conf" </Directory> </VirtualHost>Create vhost file
C:/xampp/apache/conf/vhost/php56-php-multiple-version.local.conf<VirtualHost *:80> ServerAdmin [email protected] DocumentRoot "C:/Projects/php-multiple-version/" ServerName php56-php-multiple-version.local ErrorLog "logs/php56-php-multiple-version.local-error.log" CustomLog "logs/php56-php-multiple-version.local.log" common FcgidInitialEnv PHPRC ${PHP_56_RC} <Directory "C:/Projects/php-multiple-version/"> Define PHP_CGI ${PHP_56_CGI} Include "conf/php.d/php_cgi.conf" </Directory> </VirtualHost>add to end of file
C:\Windows\System32\drivers\etc\hosts127.0.0.1 php72-php-multiple-version.local 127.0.0.1 php56-php-multiple-version.localcreate file
C:/Projects/php-multiple-version/index.php<?php phpinfo();
Start xampp and open your browser: http://php72-php-multiple-version.local and http://php56-php-multiple-version.local
-
When stop apache from XAMPP control panel, php-cgi still running in background. to stop it, run this command via cmd
taskkill /F /IM php-cgi.exe /T -
If you want to run php by command, you can create file .bat like that:
php72.batC:/xampp/php-7.2.0/php.exe %*and run to test:
php72 -r "phpinfo();"