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.exe
C:\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.