简体   繁体   English

如何获得apache的版本?

[英]How to get apache's version?

When I try to run apache_get_version() function on my website, I get an error: 当我尝试在我的网站上运行apache_get_version()函数时,出现错误消息:

Fatal error: Uncaught Error: Call to undefined function apache_get_version() in /srv/www/mywebsite.com/index.php:44 Stack trace: #0 {main} thrown in /srv/www/mywebsite.com/index.php on line 44 致命错误:未捕获错误:调用/srv/www/mywebsite.com/index.php:44中未定义的函数apache_get_version()堆栈跟踪:#0 {main}抛出于/srv/www/mywebsite.com/index.php在第44行

However this works in my localhost. 但是,这在我的本地主机工作。 I tried 我试过了

function apache_version()
{
    $ver = explode(" ",$_SERVER["SERVER_SOFTWARE"],3);
    return ($ver[0] . " " . $ver[1]);
}
echo apache_version();

This should echo the server version on apache though it doesn't echo the version 这应该回显apache上的服务器版本,尽管它不回显版本

From the introduction to Apache functions : 介绍到Apache函数

These functions are only available when running PHP as an Apache module. 仅当将PHP作为Apache模块运行时,这些功能才可用。

If you run PHP as CGI/FastCGI or any other SAPI, there's just no reliable way to determine Apache version because the interaction of PHP with Apache is minimum. 如果将PHP作为CGI / FastCGI或任何其他SAPI运行,则没有可靠的方法来确定Apache版本,因为PHP与Apache的交互作用是最小的。 If the server does not report it (thus you can read it somewhere at $_SERVER ) you're out of luck. 如果服务器未报告该消息(因此您可以在$_SERVER某处读取它),那么您很不走运。

You can also determine how PHP runs with phpinfo() . 您还可以确定 phpinfo() 如何运行PHP

Maybe you could try 也许你可以尝试

<?php
echo shell_exec('httpd -version');

You can use $_SERVER['SERVER_SOFTWARE'] To get the the web server you're running. 您可以使用$_SERVER['SERVER_SOFTWARE']来获取正在运行的Web服务器。 As Andrew said you can compile it yourself from here . 正如安德鲁所说,您可以从这里自己编译。 There's no way around it 没办法解决

To determine if you can read the Apache version, create a phpinfo.php file as mentioned by Álvaro González. 要确定您是否可以阅读Apache版本,请创建ÁlvaroGonzález提到的phpinfo.php文件。

<?php phpinfo(); ?>

Run the file and if the PHP Variable $_SERVER['SERVER_SOFTWARE'] is listed with a value, use the following in your PHP code: 运行该文件,如果列出了带有值的PHP变量$ _SERVER ['SERVER_SOFTWARE'] ,请在您的PHP代码中使用以下命令:

$apache_version = $_SERVER['SERVER_SOFTWARE'];
echo "$apache_version";

The reported value is dependent on the configuration and may not be listed at all. 报告的值取决于配置,可能根本没有列出。 Otherwise you might get something like Apache/2.4.29 (Unix) or Apache/2.2.22 (Win64) etc. 否则,您可能会得到类似Apache / 2.4.29(Unix)或Apache / 2.2.22(Win64)等的信息。

echo apache_get_version();

它将打印Apache的完整版本详细信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM