Oliver Spryn
Oliver Spryn

Reputation: 17368

Check if PHP is installed on Apache or IIS Server?

Is there a way to check if PHP is installed on an Apache or IIS server within the PHP environment itself?

If so, how?

Upvotes: 21

Views: 87632

Answers (5)

Nir Alfasi
Nir Alfasi

Reputation: 53565

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!

Upvotes: 30

untill
untill

Reputation: 1593

I don't know with what PHP version it became available, but try this:

if( strpos( $_SERVER['SERVER_SOFTWARE'], 'Apache') !== false) 
  echo 'Have Apache';
else
  echo 'Have some other server';

Upvotes: 8

Gabriel Ryan Nahmias
Gabriel Ryan Nahmias

Reputation: 2159

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.

Upvotes: 6

jbnunn
jbnunn

Reputation: 6355

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).

Upvotes: 0

j08691
j08691

Reputation: 208032

Create a PHP script called php.php with the content:

<?php
phpinfo();
?>

and run it from your browser. Or from command line, run:

php -v

Upvotes: 13

Related Questions