How can I get the path of the PHP binary from PHP?

Linux Only

Use the "which" command to find php.

$phpPath = exec("which php");

Note this does not guarantee the same php executable that your web server may be using, but rather the first instance that was found while looking through the paths.


You can use:

$_SERVER['_']

Also, the predefined constant PHP_BINDIR gives the directory where the PHP executable is found.

Sample on CodePad and Ideone.

It looks like, for security reasons, $_SERVER values are not exposed.

Tags:

Php

Path

Bin