如何查看Debian机器上安装了Apache的哪个版本?

有这样做的命令吗?


当前回答

Apache的一些安装是fubar(想想Oracle对它的包装,OHS),不理解-V标志,也不能直接调用而不会遇到丢失库错误。

最简单的方法是在httpd二进制文件和grep上使用strings命令(binutils的一部分)来获取可能类似于版本的字符串。例如,假设你的httpd二进制文件在目录/foo/bar下:

$ strings /foo/bar/httpd  | grep 2.2
GLIBC_2.2.5
Oracle-HTTP-Server/2.2.22 (Unix)
Success_Accepted_202
202 Accepted

大多数二进制文件(不是全部)以静态字符串的形式包含它们的版本(至少是主版本)。这是我获取版本的常用方法(或者用来证实二进制的帮助信息与实际情况是否相符)。

其他回答

我使用红帽Linux和以下命令工作:

httpd -V

You can use apachectl -V or apachectl -v. Both of them will return the Apache version information! xgqfrms:~/workspace $ apachectl -v Server version: Apache/2.4.7 (Ubuntu) Server built: Jul 15 2016 15:34:04 xgqfrms:~/workspace $ apachectl -V Server version: Apache/2.4.7 (Ubuntu) Server built: Jul 15 2016 15:34:04 Server's Module Magic Number: 20120211:27 Server loaded: APR 1.5.1-dev, APR-UTIL 1.5.3 Compiled using: APR 1.5.1-dev, APR-UTIL 1.5.3 Architecture: 64-bit Server MPM: prefork threaded: no forked: yes (variable process count) Server compiled with.... -D APR_HAS_SENDFILE -D APR_HAS_MMAP -D APR_HAVE_IPV6 (IPv4-mapped addresses enabled) -D APR_USE_SYSVSEM_SERIALIZE -D APR_USE_PTHREAD_SERIALIZE -D SINGLE_LISTEN_UNSERIALIZED_ACCEPT -D APR_HAS_OTHER_CHILD -D AP_HAVE_RELIABLE_PIPED_LOGS -D DYNAMIC_MODULE_LIMIT=256 -D HTTPD_ROOT="/etc/apache2" -D SUEXEC_BIN="/usr/lib/apache2/suexec" -D DEFAULT_PIDLOG="/var/run/apache2.pid" -D DEFAULT_SCOREBOARD="logs/apache_runtime_status" -D DEFAULT_ERRORLOG="logs/error_log" -D AP_TYPES_CONFIG_FILE="mime.types" -D SERVER_CONFIG_FILE="apache2.conf" You may be more like using apache2 -V or apache2 -v. It seems easier to remember! xgqfrms:~/workspace $ apache2 -v Server version: Apache/2.4.7 (Ubuntu) Server built: Jul 15 2016 15:34:04 xgqfrms:~/workspace $ apache2 -V Server version: Apache/2.4.7 (Ubuntu) Server built: Jul 15 2016 15:34:04 Server's Module Magic Number: 20120211:27 Server loaded: APR 1.5.1-dev, APR-UTIL 1.5.3 Compiled using: APR 1.5.1-dev, APR-UTIL 1.5.3 Architecture: 64-bit Server MPM: prefork threaded: no forked: yes (variable process count) Server compiled with.... -D APR_HAS_SENDFILE -D APR_HAS_MMAP -D APR_HAVE_IPV6 (IPv4-mapped addresses enabled) -D APR_USE_SYSVSEM_SERIALIZE -D APR_USE_PTHREAD_SERIALIZE -D SINGLE_LISTEN_UNSERIALIZED_ACCEPT -D APR_HAS_OTHER_CHILD -D AP_HAVE_RELIABLE_PIPED_LOGS -D DYNAMIC_MODULE_LIMIT=256 -D HTTPD_ROOT="/etc/apache2" -D SUEXEC_BIN="/usr/lib/apache2/suexec" -D DEFAULT_PIDLOG="/var/run/apache2.pid" -D DEFAULT_SCOREBOARD="logs/apache_runtime_status" -D DEFAULT_ERRORLOG="logs/error_log" -D AP_TYPES_CONFIG_FILE="mime.types" -D SERVER_CONFIG_FILE="apache2.conf"

另一种方法是在基于debian的系统上检查包(包括Apache)安装的版本,我们可以使用:

apt-cache policy <package_name>

例如Apache

apt-cache policy apache2

它将显示如下内容(查看Installed行):

$ apt-cache policy apache2
apache2:
  Installed: (none)
  Candidate: 2.2.22-1ubuntu1.9
  Version table:
     2.2.22-1ubuntu1.9 0
        500 http://hk.archive.ubuntu.com/ubuntu/ precise-updates/main amd64 Packages
        500 http://security.ubuntu.com/ubuntu/ precise-security/main amd64 Packages
     2.2.22-1ubuntu1 0
        500 http://hk.archive.ubuntu.com/ubuntu/ precise/main amd64 Packages

我尝试运行命令“httpd -V”和“apachectl -V”,但我无法执行,并得到错误:

-ksh: php: not found[没有这样的文件或目录]

然后我尝试了另一种方法。我进入服务器上的Apache目录,然后尝试执行命令:

./apachectl -v

这为我工作,并返回输出:

Server version: Apache/2.2.20 (Unix)
Server built:   Sep  6 2012 17:22:16

我希望这能有所帮助。

当然,在shell中输入/usr/sbin/apache2 -v是最好和最快的方法,顺便说一下,这里还有另一种选择,以防你的服务器中也有PHP,你有兴趣在快速编程步骤中收集Apache版本(以及更多信息)。

在你的Apache web根文件夹(或任何你喜欢的文件夹)中创建一个info.php文件,并在里面写这些:

<?php
    phpinfo();
?>

现在转到yoursite.com/info.php(或localhost/info.php用于本地计算机)。

你会在PHP变量部分看到你的Apache版本,这里有一个例子:

Phpinfo()示例转储页面

另外,请注意,这些步骤显然适用于任何与PHP集成的web服务器,所以它并不局限于Apache,一旦创建了页面,在开发时就可以方便地使用(只是不要忘记在生产环境中删除它!!)