How to change PHP cli version for Windows
Home » BLOG » Web development » How to change PHP cli version for Windows

How to change PHP cli version for Windows

category:  Web development

Recently, I am building a online store with Laravel 8. In order to work with Laravel 8, I need to upgrade my PHP cli. Right now, I have PHP 7.1.33 (cli) on my computer. You can check your own PHP cli at the terminal as below.

$ php -v
 PHP 7.1.33 (cli) (built: Oct 23 2019 09:24:14) ( ZTS MSVC14 (Visual C++ 2015) x64 )
 Copyright (c) 1997-2018 The PHP Group
 Zend Engine v3.1.0, Copyright (c) 1998-2018 Zend Technologies

Now I will head to environment variables and change the PHP cli path at system variables section. This is how I setup my environment development for all PHP web application and WordPress. This way, I can access PHP cli, composer, nodejs and more from anywhere in my computer.

Access Environment Variables

To access the environment variables, you just search “environment variable” keyword from search icon on task bar. Below where to access environment variables.

Environment Variables for Windows
Environment Variables for Windows

After clicking on Environment Variables button, you will see this popup.

Edit environment variables
Edit environment variables

Change PHP cli version path

You will edit the Path variable. Basically you just add the PHP cli version you want into Path variable.

change php cli version

For me, I have a bunch of PHP versions in Wampserver including PHP 7.4.0. In order to change the PHP cli version, in my case, I just edit the PHP path from 7.1.33 to 7.40.

So for Path variable, I change from “E:\wamp64\bin\php\php7.1.33” to “E:\wamp64\bin\php\php7.4.0“.

Now, close your terminal and reopen again. Then check PHP cli version. You should see the PHP cli version as 7.4.0 now as shown below.

$ php -v
 PHP 7.4.0 (cli) (built: Nov 27 2019 10:14:18) ( ZTS Visual C++ 2017 x64 )
 Copyright (c) The PHP Group
 Zend Engine v3.4.0, Copyright (c) Zend Technologies

Install multiple PHP versions on Wampserver

With Wampserver, you can install multiple PHP, MySQL, Maria and PHPmyadmin versions as much as you like. Simply follow How to install multiple PHP versions in Wampserver