Coding Notes

Cmd File For Different PHP Versions on Windows

I’ve been working with some clients who ran Laravel under older PHP versions than I have installed so I needed a quicker way to access the correct versions in command prompt.

1. Make sure you download the PHP versions you need or use wampserver. I needed 2 different versions PHP 7.3 and PHP 7.4

2. Create a directory called C:\Bin or something similar and add it to the %PATH% variable.

3. Create the command file in C:\Bin

c:\bin\php73.cmd

@call <path to \php7.3.21\php.exe> %*

c:\bin\php74.cmd

@call <path to \php7.4.9\php.exe> %*

I also needed composer so I created c:\bin\php74composer.cmd

@call <path to \php7.4.9\php.exe> C:\ProgramData\ComposerSetup\bin\composer.phar %*

3. Use command prompt to access the executables.

C:\>php74 -v
PHP 7.4.9 (cli) (built: Aug  4 2020 11:52:41) ( ZTS Visual C++ 2017 x64 )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies

C:\>php73 -v
PHP 7.3.21 (cli) (built: Aug  4 2020 11:21:19) ( ZTS MSVC15 (Visual C++ 2017) x64 )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.21, Copyright (c) 1998-2018 Zend Technologies

C:\>php74composer -v
______
/ ____/___ ____ ___ ____ ____ ________ _____
/ / / __ \/ __ `__ \/ __ \/ __ \/ ___/ _ \/ ___/
/ /___/ /_/ / / / / / / /_/ / /_/ (__ ) __/ /
\____/\____/_/ /_/ /_/ .___/\____/____/\___/_/
/_/
Composer version 2.1.3 2021-06-09 16:31:20

 

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.