Is there a way to check if PHP is installed on an Apache or IIS server within the PHP environment itself?
If so, how?
create a file (say info.php) with the following content on an accessible path and try to browse it:
<?php
phpinfo();
?>
@Alfabravo is correct: don't forget to delete the file from the server after using it!
<?php echo $_SERVER['SERVER_SOFTWARE']; ?>The virtually most definitive answer possible (there are other similar possibilities) is:
function on_iis() {
$sSoftware = strtolower( $_SERVER["SERVER_SOFTWARE"] );
if ( strpos($sSoftware, "microsoft-iis") !== false )
return true;
else
return false;
}
Now, just use on_iis() whenever you want to know.
You can also find out via the $_SERVER['DOCUMENT_ROOT'], sort of:
Read http://www.helicron.net/php/
(Basically, according to the article, Apache sets the document root with a valid variable, and IIS does not).
$_SERVER['SERVER_SOFTWARE'];