How do i change php version in windows terminal?

Old question I know, but just to add some additional information:

  • WAMP is used only on Microsoft Windows Operating Systems.
  • Changing the version of PHP used through the left-click -> PHP -> Version menu changes the version used by Apache to server your site.
  • Changing the version of PHP used through the right-click -> Tools -> Change PHP CLI Version menu changes the version used by WAMP's PHP CLI.

Note: It is important to understand that the "PHP CLI Version" is used by WAMP's own internal PHP scripts. This "PHP CLI Version" has nothing to do with the version you wish to use for your scripts, Composer or anything else.

For your scripts to work with the version you require, you need to add it's path to the Users Environmental Path. You could add it to the Systems environmental Path but the Users Path is the recommended option.

From WAMP v3.1.2, it would display an error when it detect reference to a PHP path in the System or User Environmental Path. This was to stop confusion such as you were experiencing. Since v3.1.7 the display of this error can now be optionally displayed through a selection in the WampSettings menu.

As indicated in previous answers, adding an installed PHP path (such as "C:\wamp64\bin\php\php7.2.30") to the Users Environmental Path is the correct approach. PS: As the value of the Users Environmental Path is a string, all paths added must be separated with a semi-colon (;)

After experiencing the exact same problem (IE: Choosing which version of PHP I wanted Composer to use), I created a script which could easily and rapidly switch between PHP CLI Versions depending on what project I was working on.

The Windows batch script "WampServer-PHP-CLI-Version-Changer" can be found at https://github.com/custom-dev-tools/WampServer-PHP-CLI-Version-Changer

I hope this helps others.

Good luck.

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.

How do i change php version in windows terminal?
Environment Variables for Windows

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

How do i change php version in windows terminal?
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.

How do i change php version in windows terminal?

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

Troubleshoot

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.

How do I update PHP version in terminal?

In short what you need to do is:.
Ensure the php packages for the version you want are installed..
Update any configuration for that PHP version..
Update your web server configuration to point to the correct PHP version..
Point PHP CLI to the correct PHP version..
Restart your web server and php-fpm..
Mask the old php-fpm daemon..

How do I switch between multiple PHP versions in Windows?

Steps to change port:.
Change the config file for the MySQL in “my. ini” file..
Change the port to 3307..
Run the code: PHP. ... .
Save the above code in “htdocs” folder of the XAMPP folder for the new and older version..
Save in “htdocs” folder of the XAMPP folder..
Similarly with XAMPP_1_8_2..

How do I change the default PHP in Windows?

I found a very easy way to switch php versions:.
Search for system environment variable..
Click on "Environment variables".
Under "System variables" select path and click on edit..
Move the PHP version folder you want to use before the other one. So for example: php 7.0 will now be used:.

What version of PHP do I have terminal windows?

1. Type the following command, replacing [location] with the path to your PHP installation. 2. Typing php -v now shows the PHP version installed on your Windows system.