Home>
Question

How can I get the version of PHP I put in later to run when I run PHP from the command prompt?

Symptoms

I put php8.0.0 in windows10 by myself and the path was originally included
PHP 7.1.29 (cli) (built: May 1 2019 14:15:48) (NTS MSVC14 (Visual C ++ 2015) x86)
The version does not change from.

What i did
  1. Rename php-8.0.0 to php in C: \ php and save.
  2. Added C: \ php to the system environment variable Path.
  3. Reboot.
Confirmation

A different version is displayed with php -v.

C: \ Users \ user>php -v
PHP 7.1.29 (cli) (built: May 1 2019 14:15:48) (NTS MSVC14 (Visual C ++ 2015) x86)
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2018 Zend Technologies

If i specify a directory and execute it, the desired version will be displayed.

C: \ Users \ user>C: \ php \ php -v
PHP 8.0.0 (cli) (built: Nov 24 2020 22:02:57) (ZTS Visual C ++ 2019 x64)
Copyright (c) The PHP Group
Zend Engine v4.0.0-dev, Copyright (c) Zend Technologies
  • Answer # 1

    Path is searched in order from the front, so if an exe with the same name is found before the added directory, that will be executed.
    Please review the description of Path.

  • Answer # 2

    Added C: \ php to the system environment variable Path.

    It may be a problem of the additional position of (the higher the priority is at the beginning).
    Put it before other PHP directories.

    reference:where phpResult of