How to determine path to php.exe on Windows - search default paths How to determine path to php.exe on Windows - search default paths python python

How to determine path to php.exe on Windows - search default paths


If the user has added PHP's bin folder to the system PATH, then you should just be able to try and execute php -v to check that it's present.

If you want to obtain the full path to the PHP executable and the target system is Windows Server 2003 or later (so Windows Vista, and Windows 7) then you could use the WHERE command, i.e.:

C:\> where php.exeC:\Program Files (x86)\WAMP\bin\php\php5.3.5\php.exe

Also see possibly related question: Is there an equivalent of 'which' on the Windows command line?.

If you are really desperate to find any file on the user's computer, you could try executing the equivalent of a find - but it's going to be slooow!

C: && cd \ && dir /s /b php.exe


From PHP 5.4 and later, you can use the PHP_BINARY constant.


On powershell or commad promptphp -r "echo PHP_VERSION;" gives the version

See other PHP constantas:https://www.php.net/manual/es/reserved.constants.php

to answer your question

php -r "echo PHP_BINARY;" gives the full path to php.exe

if needed, to remove the php.exe

php -r "echo str_replace('php.exe', '', PHP_BINARY);"