How to get path of the php binary on server where it is located

It's usually /usr/bin/php but you could try to capture and parse the output of the command 'whereis php' or 'which php''.

Or better yet, use the constant PHP_BINARY if it is available. Have a look here.


Most of the time, the PHP_BINARY predefined constant should do the job.

If you need something more developed, you can make use of Symfony's Process component, by using its PhpExecutableFinder class:

// composer require symfony/process

use Symfony\Component\Process\PhpExecutableFinder;

(new PhpExecutableFinder)->find();