0

How can I extract the Apache version number?

I would like to then use this number to compare it against a value in a configuration requirement file for a minimum Apache version as part of an automated installation procedure.

I use $ENV{'SERVER_SOFTWARE'} which gives me:Apache/2.2.3 (Debian) DAV/2 SVN/1.4.2 mod_python/3.2.10 Python/2.4.4 PHP/5.2.0-8+etch16 mod_perl/2.0.2 Perl/v5.8.8)

Is this the format: Apache/2.2.3 consistent across all versions or does it vary e.g. for Apache 1.3 and future versions of Apache?

HopelessN00b
  • 53,795
  • 33
  • 135
  • 209
therobyouknow
  • 471
  • 4
  • 8
  • 18
  • 1
    I would first question whether you really need to support a minimum version number of Apache or whether your software will work on earlier versions (or could be made to). – WheresAlice Jan 12 '10 at 17:58
  • I agree. But I feel I need to "put a stake in the ground", be specific about what the configuration would be so that is is straightforward for people about what is required. The software is deployed in a non-public corporate environment on limited amount of machines. It is probably not worth testing the software on earlier versions if none of the machines run this. Sorry for not adding this detail earlier. – therobyouknow Jan 12 '10 at 22:36

1 Answers1

1

Do you want to get this information locally or from remote? You could execute the following command as well:

$ httpd -v
Server version: Apache/2.2.13 (Unix)
Server built:   Aug 18 2009 06:16:17
Raffael Luthiger
  • 2,001
  • 2
  • 17
  • 26
  • That would be useful in other scenarios +1. I need a solution to run within Perl code and my original suggestion $ENV{'SERVER_SOFTWARE'} is closest so far. Assuming the Apache version is always presented in the same text format, I could use a regular expression to extract it out from the rest of the string. – therobyouknow Jan 12 '10 at 22:38
  • 1
    As described here you could run my command within perl too: http://www.perlmonks.org/?node_id=57193 You just need to write it like mentioned on this page (or with the command "exec"). But yes, your solution is probably better. But you can not always trust it because it can be changes as described here: http://httpd.apache.org/docs/1.3/misc/FAQ.html#serverheader – Raffael Luthiger Jan 12 '10 at 23:39