Home > OS >  Get Apache installation path via PHP in Windows environment
Get Apache installation path via PHP in Windows environment

Time:11-09

How do I use PHP 8.0 to determine the Apache installation path in a Windows environment?

No: I know where it is manually, I need to do this programmatically.

CodePudding user response:

There was nothing in $_SERVER and I had to resort to digging through phpinfo(). The following allows you to reuse phpinfo() as $pinfo if you need to find other bits of information. Additionally PHP does not support the JavaScript index style (e.g. explode()[index]) on I think 7.2 and older so anyone stuck on those older versions may have to re-code the two explode in to separate lines.

//If you need additional items you can refer ONCE to $pinfo:
ob_start();
phpinfo();
$pinfo = ob_get_contents();
ob_end_clean();

if (PHP_OS == 'WINNT')
{
 //explode()[index] will not work on PHP ~7.2 and older
 echo explode('<', explode('>Server Root </td><td >', $pinfo, 2)[1], 2)[0];
}
  • Related