Allow to use and switch between different versions of PHP for Xampp on Windows OS.
Use and switch between different versions of PHP for Xampp on Windows OS.
Xampp is an easy to install Apache distribution containing MariaDB, PHP, and Perl. It has been around for more than 10 years – there is a huge community behind it. Currently, there are many other applications launched with more advantages. However, many people still love Xampp because of its ease of use. The problem is that quite a lot of people have not exploited the full power of Xampp.
Therefore, I have created 2 separate projects to take full advantage of what Xampp has to add to the features that many people desire to have in Xampp:
- One is the feature that allows the use of different versions of PHP (this project).
- One is the vhosts management feature, comes with self-signed SSL certificates (see here).
With this project, using and switching between different PHP versions for Xampp became easy. This will be useful for those who want to ensure their applications work smoothly on different PHP platforms or those who are researching PHP programming.
Note: Currently this project only supports Windows users.
- Install and manage various PHP builds for a single Xampp version.
- Switch between different versions of PHP quickly and easily.
Look at one of the following topics to learn more about Xampp PHP Switcher.
- Add other PHP versions to your Xampp
Xampp PHP Switcher is compatible with all Xampp versions using PHP 5.4 or higher.
Xampp PHP Switcher takes full advantage of what's included in Xampp, nothing more needed. So, you just need following things:
- Xampp installed successfully (this project does not yet support the portable Xampp version).
- Added the path to PHP directory of Xampp into Windows Path Environment Variable.
- (Optional) Installed Composer.
Note: See here to know how to add Windows Path Environment Variable.
There are two installation methods, via Composer or manual download. It is recommended to use the method via Composer if you already have it installed.
- Open a terminal.
- Navigate to the directory you want to install Xampp PHP Switcher into
(example: cd /D D:\).
- Run composer create-project command:
$ composer create-project jackiedo/xampp-php-switcher xphp "1.*"
- Download the latest release
- Extract the archive to a shared location
(example: D:\xphp). Note: Should not place in
C:\Program Filesor anywhere else that would require Administrator access for modifying configuration files.
- Open a terminal in Administrator mode
(run as Administrator).
- Navigate to the directory you have placed Xampp PHP Switcher
(example: cd /D D:\xphp).
- Execute the command
xphp installand follow the required steps.
- Exit terminal (to remove temporary environment variables).
Note: See here to know how to to open the command prompt as Administrator.
After successfully installing Xampp PHP Switcher, by default you will have a built-in PHP version of your Xampp. In order to use other versions of PHP, we will proceed to add those builds to the repository. This will also be easily done. But you need to keep in mind the following requirements:
- Only add builds downloaded from the Xampp official website, or builds that have been added to the Xampp PHP Switcher repository.
- Only builds with the same architecture (32 or 64 bit runtime) may be added to the current build.
We perform each of the following steps:
Execute the following command:
$ xphp info current
View the information in Architecture section and remember it.
- Download compatible Xampp builds from Official Download page at here.
- When downloading, note that the architecture of the build to download must be the same as the current build architecture we have just seen above.
- Do not download the Portable builds, nor download the installer (.exe).
- After downloading, extract it to somewhere on our computer and note the path to the PHP directory inside the newly extracted Xampp directory.
Compatible items to download
xphp add command:
$ xphp add "drive:\path\to\above\php\directory"
or more simply with the second syntax:
$ xphp add
And then provide the link above when requested.
Note: If you use the first syntax, you should put the path in the double quotes (") to avoid the errors of the effect of whitespaces.
And now we have many different versions of PHP to use. We can switch between versions with the
xphp switch command.
When we use the
xphp add command, Xampp PHP Switcher will do the following:
- Copy the entire directory containing the PHP build into the repository.
- Conduct standardization of the paths in some files of new PHP build so that it is compatible with the path to our Xampp directory.
- Create a file containing the PHP build archive information (with name ".storage") and place it into the directory of the build.
The process of standardize paths is done based on a file named "need_standardize.lst" located in the project directory. Currently, this file has supported the path standardization for PHP builds from versions 5.4 (Xampp 1.8.3) to 7.4 (Xampp 7.4.x). Every time a new version of Xampp is released, this file will be checked and updated. You only need to copy the whole new content of this file and overwrite your existing file in your Xampp PHP Switcher directory. Or you can download the project source code here and extract (overwrite) to your Xampp PHP Switcher directory.
Because of a path to the Xampp PHP Switcher application directory has been added to the Windows Path Environment Variables during the installation process, now you can just open the terminal
(no need to open in Administrator mode anymore) anywhere and excute one of the following
$ xphp help
$ xphp info current
$ xphp info [VERSION]
$ xphp info 5.6.40
Note: The VERSION parameter is optional. If you do not pass it to the command statement, you will also be asked to enter this information later.
$ xphp list
$ xphp remove [VERSION]
$ xphp remove 5.6.40
$ xphp add [PATH_TO_PHP_DIRECTORY]
$ xphp add "D:\download\xampp-win32-5.5.19-0-VC11\php"
$ xphp switch [VERSION]
$ xphp switch 5.5.19
MIT © Jackie Do