How can I get the full path to php interpreter from a php script (no command line access).
What I need to do is:
$foo = "/usr/bin/php";
echo $foo;
But I need to get the path first so I can assign it to foo.
If you have a solution that works on both Windows and nix even better but if not, nix would be fine.
Before you ask,
The problem is that using whatever it outputs doesn't work. For example PHP_BINDIR will output /usr/bin but using /usr/bin/php won't help. The full code is:
exec("php-cli $path_to_file > /dev/null 2>/dev/null &");
But even using the /usr/bin/php-cli doesn’t work even though it tells me that. I have to use:
exec("/opt/php52/bin/php-cli $path_to_file > /dev/null 2>/dev/null &");
For this particular host for example.
From below example, we can see the PHP executable file path is /usr/bin/php , and it is linked to /www/server/php/73/bin/php file ( this is the real PHP executable file ). If whereis command returns multiple PHP install path, then you can run which command to get current PHP executable file path.
You can find the PHP binary path with this constant:
PHP_BINDIR
As of PHP 5.4, you can get the path to the executable actually running currently with this constant:
PHP_BINARY
http://php.net/manual/en/reserved.constants.php
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With