Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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?

share|improve this question
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). –  kaerast 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 Answer 1

up vote 1 down vote accepted

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
share|improve this answer
    
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: 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: httpd.apache.org/docs/1.3/misc/FAQ.html#serverheader –  Raffael Luthiger Jan 12 '10 at 23:39
    
+1 comment, +1 answer, and accepted. Sorry took so long. –  therobyouknow Dec 21 '10 at 10:00

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.