How can I get the bin path of php from PHP? I saw it in phpinfo(); but I need another method that gets it in linux and windows systems.
+1
A:
You can use:
$_SERVER['_']
also the constant
PHP_BINDIR
gives the directory where the php executable is found.
Looks like for security reasons $_SERVER
values is not exposed.( I guess..Plz correct me if I'm wrong).
codaddict
2010-10-08 10:11:21
In Windows, the PHP_BINDIR constant seems to point to "C:\php5" even if php is in a totally different directory, like for me "C:\dev\php". Here, PHP is setup as an apache module.
SirDarius
2010-10-08 10:16:43
A:
A method using environment variables, assuming the php executable is in the system path.
function getPHPExecutableFromPath() {
$paths = explode(PATH_SEPARATOR, getenv('PATH'));
foreach ($paths as $path) {
$php_executable = $path . DIRECTORY_SEPARATOR . "php" . (isset($_SERVER["WINDIR"]) ? ".exe" : "");
if (file_exists($php_executable) && is_file($php_executable)) {
return $php_executable;
}
}
return FALSE; // not found
}
SirDarius
2010-10-08 10:22:33