Check if PHP is installed on Apache or IIS Server?

后端 未结 5 1913
心在旅途
心在旅途 2020-12-10 02:35

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条回答
  • 2020-12-10 03:10

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

    0 讨论(0)
  • 2020-12-10 03:15

    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.

    0 讨论(0)
  • 2020-12-10 03:26

    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!

    0 讨论(0)
  • 2020-12-10 03:28

    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';
    
    0 讨论(0)
  • 2020-12-10 03:34

    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
    
    0 讨论(0)
提交回复
热议问题