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 an 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 the environment variables and change the PHP CLI path in the System variables section. This is how I set up my environment development for all PHP web applications and WordPress. This way, I can access PHP CLI, composer, nodejs, and more from anywhere on my computer.

Access Environment Variables

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

Environment Variables for Windows
Environment Variables for Windows

After clicking on the 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 the Path variable.

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.

Here is my Path variable, I change from “E:\wamp64\bin\php\php7.1.33” to “E:\wamp64\bin\php\php7.4.0“.

Now, you will kill all the opened terminals if you leave them open, and reopen VSCode again. Then check the PHP CLI version by the command line below. You should see the PHP CLI version you just change in the System variables now.

$ 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


Still see the old PHP CLI version in your terminal?

If you still see the PHP CLI old version in the terminal, make sure you terminate the opened terminal (bash terminal) in VScode and open a new terminal. Then check the PHP CLI version on the new terminal.

Have many PHP versions in System variables

If you have more than one PHP version are set in the System variables, you just move the PHP version you want to use and move it above other PHP versions. So that the terminal can pick the first PHP version from the System variables.

Install multiple PHP versions on Wampserver

With WampServer, you can install multiple PHP, MySQL, Maria, and PHPmyadmin versions as much as you like. Because you can select which version you want when you develop your projects. Simply follow How to install multiple PHP versions in Wampserver