检查 PHP 是否安装在 Apache 或 IIS 服务器上?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9486261/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Check if PHP is installed on Apache or IIS Server?
提问by Oliver Spryn
Is there a way to check if PHP is installed on an Apache or IIS server within the PHP environment itself?
有没有办法检查 PHP 环境本身内的 Apache 或 IIS 服务器上是否安装了 PHP?
If so, how?
如果是这样,如何?
回答by alfasin
create a file (say info.php) with the following content on an accessible path and try to browse it:
在可访问的路径上创建一个包含以下内容的文件(比如 info.php)并尝试浏览它:
<?php
phpinfo();
?>
@Alfabravo is correct: don't forget to delete the file from the server after using it!
@Alfabravo 是正确的:使用后不要忘记从服务器中删除文件!
回答by j08691
Create a PHP script called php.php with the content:
使用以下内容创建一个名为 php.php 的 PHP 脚本:
<?php
phpinfo();
?>
and run it from your browser. Or from command line, run:
并从您的浏览器运行它。或者从命令行运行:
php -v
回答by untill
I don't know with what PHP version it became available, but try this:
我不知道它可用的 PHP 版本是什么,但试试这个:
if( strpos( $_SERVER['SERVER_SOFTWARE'], 'Apache') !== false)
echo 'Have Apache';
else
echo 'Have some other server';
回答by Gabriel Ryan Nahmias
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.
现在,on_iis()
只要您想知道就使用。
回答by jbnunn
You can also find out via the $_SERVER['DOCUMENT_ROOT'], sort of:
您还可以通过 $_SERVER['DOCUMENT_ROOT'] 查找,例如:
Read http://www.helicron.net/php/
阅读http://www.helicron.net/php/
(Basically, according to the article, Apache sets the document root with a valid variable, and IIS does not).
(基本上,根据文章,Apache 使用有效变量设置文档根目录,而 IIS 没有)。