21

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

If so, how?

5 Answers 5

30

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!

Sign up to request clarification or add additional context in comments.

2 Comments

...And then, delete the file from the server after using it.
Looks like I can also do <?php echo $_SERVER['SERVER_SOFTWARE']; ?>
13

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

Comments

8

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';

Comments

6

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.

Comments

0

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

2 Comments

Or also $_SERVER['SERVER_SOFTWARE'];
IIS sometimes does return a valid DOCUMENT_ROOT - it depends on the server config.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.