One of the issues that I have faced is having and running multiple versions of PHP with ease. I currently have 6 versions of PHP on my development machine. Before, to invoke the non-primary version, I would have to call it by the full path. I’ve tried making a common directory with symlinks and with shortcuts to the executables, but that never worked.
The issue with shortcuts is that Windows shortcuts are not, by their nature, executable. This means that they will not be a valid target in the command prompt. They showed promise because I could get the “start in”, or the folder that the program is based in.
That was important because with symlinks I would get the error that the DLL files were not found. They were not in the common directory, because I could not keep 6 versions of the same files with the same names in the same folder.
I had to find another solution. After a bit of Googling, I found some help on Stack Overflow. Someone wanted to know how to have a shortcut to their Chrome exe file outside of the Chrome installation folder. They had the same errors that I was getting, so I was able to use that solution.
All of my PHP installations are in C:\PHP
.
As you can see, I have the non-thread-safe and thread-safe versions of 7.0, 7.1, and 7.2.
My goal was to be able to call my default PHP from the command line in the normal sense, and to call a default 7.2 (et al) version (which for me is non-thread-safe), and to call any of the six specifically.
The CurrentVersion
folder is in my system Path.
I went with the .cmd
extension, but .bat works as well. In the end, I created 10 .cmd
files, so I can address the 6 versions in 10 ways.
Lets take a look inside one of the specific .cmd
files, php-7.2-nts.cmd
1 |
@"C:\PHP\php-7.2.2-nts-Win32-VC15-x64\php.exe" %* |
The six version specific ones all look like this one here.
For my ones where I specify version number but not threading, and for the default, I point to the other .cmd
files. Here is what is inside php-7.2.cmd
1 |
@"C:\PHP\CurrentVersion\php-7.2-nts.cmd" %* |
And php.cmd
1 |
@"C:\PHP\CurrentVersion\php-7.2.cmd" %* |
Only 6 out of the 10 point to an actual exe
file. This is to save me some time when I update to the latest revisions.
Here is the way the pointing works out:
1 2 3 4 5 6 7 8 9 10 11 12 |
php-7.2-nts.cmd -> C:\PHP\php-7.2.2-nts-Win32-VC15-x64\php.exe php-7.2-zts.cmd -> C:\PHP\php-7.2.2-Win32-VC15-x64\php.exe php-7.1-nts.cmd -> C:\PHP\php-7.1.14-nts-Win32-VC15-x64\php.exe php-7.1-zts.cmd -> C:\PHP\php-7.1.14-Win32-VC15-x64\php.exe php-7.0-nts.cmd -> C:\PHP\php-7.0.27-nts-Win32-VC15-x64\php.exe php-7.0-zts.cmd -> C:\PHP\php-7.0.27-Win32-VC15-x64\php.exe ----- php-7.2.cmd -> php-7.2-nts.cmd -> C:\PHP\php-7.2.2-nts-Win32-VC15-x64\php.exe php-7.1.cmd -> php-7.1-nts.cmd -> C:\PHP\php-7.1.14-nts-Win32-VC15-x64\php.exe php-7.0.cmd -> php-7.0-nts.cmd -> C:\PHP\php-7.0.27-nts-Win32-VC15-x64\php.exe ----- php.cmd -> php-7.2.cmd -> php-7.2-nts.cmd -> C:\PHP\php-7.2.2-nts-Win32-VC15-x64\php.exe |
This is what it looks like in the command prompt:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
C:\PHP\CurrentVersion>php -v PHP 7.2.2 (cli) (built: Jan 31 2018 19:31:15) ( NTS MSVC15 (Visual C++ 2017) x64 ) Copyright (c) 1997-2018 The PHP Group Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies C:\PHP\CurrentVersion>php-7.2 -v PHP 7.2.2 (cli) (built: Jan 31 2018 19:31:15) ( NTS MSVC15 (Visual C++ 2017) x64 ) Copyright (c) 1997-2018 The PHP Group Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies C:\PHP\CurrentVersion>php-7.2-zts -v PHP 7.2.2 (cli) (built: Jan 31 2018 19:31:17) ( ZTS MSVC15 (Visual C++ 2017) x64 ) Copyright (c) 1997-2018 The PHP Group Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies C:\PHP\CurrentVersion>php-7.0-zts -v PHP 7.0.27 (cli) (built: Jan 2 2018 13:49:50) ( ZTS ) Copyright (c) 1997-2017 The PHP Group Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies C:\PHP\CurrentVersion>php-7.1 -v PHP 7.1.14 (cli) (built: Jan 31 2018 00:14:33) ( NTS MSVC14 (Visual C++ 2015) x64 ) Copyright (c) 1997-2018 The PHP Group Zend Engine v3.1.0, Copyright (c) 1998-2018 Zend Technologies |