Skip to content

Instantly share code, notes, and snippets.

@ozh
Created February 20, 2021 13:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ozh/40bd4ad076c70624fc33ca04671c79b2 to your computer and use it in GitHub Desktop.
Save ozh/40bd4ad076c70624fc33ca04671c79b2 to your computer and use it in GitHub Desktop.
XAMPP PHP 7.4 and PHP 8

Step 1: install XAMPP 7.4.1, make it work :) At this point you have C:/yourdir/xampp and in particular C:/yourdir/xampp/php and C:/yourdir/xampp/apache/conf/extra

Step 2 : download XAMPP 8.0.1, as a zip archive, not a self executable install Don't install it. Instead,

  • extract the content of the xampp/php directory and put it in C:/yourdir/xampp/php8
  • extract the file xampp/apache/conf/extra/httpd-xampp.conf and copy it to C:/yourdir/xampp/php and C:/yourdir/xampp/apache/conf/extra/httpd-xampp8.conf

Step 3 : edit C:/yourdir/xampp/php8/php.ini and modify the paths (eg replace all default \xampp with \yourdir\xampp). If applicable edit this C:/yourdir/xampp/php8/php.ini to match your functional C:/yourdir/xampp/php/php.ini other settings.

Step 4 : edit C:/yourdir/xampp/apache/conf/extra/httpd-xampp8.conf and modify the default paths again (Do not simply copy all conf from the existing httpd-xampp.conf file, as some directives change names)

Step 5 : job done, now you have 2 functional installs.

To switch :

  • Run xampp-control.exe and start Apache : you're running PHP 7.4.1 as previously.
  • Stop Apache
  • Switch the two PHP directories : ---- Rename C:/yourdir/xampp/php to C:/yourdir/xampp/php7 ---- Rename C:/yourdir/xampp/php8 to C:/yourdir/xampp/php
  • Switch the two Apache config files : ---- Rename C:/yourdir/xampp/apache/conf/extra/httpd-xampp.conf to C:/yourdir/xampp/apache/conf/extra/httpd-xampp7.conf ---- Rename C:/yourdir/xampp/apache/conf/extra/httpd-xampp8.conf to C:/yourdir/xampp/apache/conf/extra/httpd-xampp.conf
  • Start Apache : you're running 8.0.1

Source: https://community.apachefriends.org/f/viewtopic.php?f=16&t=80366

#!/bin/bash
####################################################################
# Switch between PHP 7.4 and PHP 8
#
####################################################################
# Colors and fancyness
RED='\033[0;31m'
NORM='\033[0m'
BOLD='\033[1m'
GREEN='\033[0;32m'
PURPLE='\033[0;35m'
# Path to XAMPP
XAMPP='/d/online/xampp7'
EXTRA="$XAMPP/apache/conf/extra/"
PHP=''
switchphp(){
if [ -d "$XAMPP/php7" ]
then
# rename "php" to "php8" and "php7" to "php"
mv "$XAMPP/php" "$XAMPP/php8"
mv "$XAMPP/php7" "$XAMPP/php"
# rename "httpd-xampp.conf" to "httpd-xampp8.conf" and "httpd-xampp7.conf" to "httpd-xampp.conf"
mv "$EXTRA/httpd-xampp.conf" "$EXTRA/httpd-xampp8.conf"
mv "$EXTRA/httpd-xampp7.conf" "$EXTRA/httpd-xampp.conf"
return
fi
if [ -d "$XAMPP/php8" ]
then
# rename "php" to "php7" and "php8" to "php"
mv "$XAMPP/php" "$XAMPP/php7"
mv "$XAMPP/php8" "$XAMPP/php"
# rename "httpd-xampp.conf" to "httpd-xampp7.conf" and "httpd-xampp8.conf" to "httpd-xampp.conf"
mv "$EXTRA/httpd-xampp.conf" "$EXTRA/httpd-xampp7.conf"
mv "$EXTRA/httpd-xampp8.conf" "$EXTRA/httpd-xampp.conf"
return
fi
echo "no PHP dir found"
}
displayphp() {
PHP=$(echo $(php --version) | cut -d "(" -f 1)
echo -e "Current version : ${BOLD}${GREEN}$PHP${NORM}"
}
displayphp
read -p "Type 'y' to switch, anything else to cancel: " SWITCH
if [ "$SWITCH" = "y" ]
then
switchphp
displayphp
echo "(might need to restart Apache)"
fi
echo " "
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment