Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

Getting Apache Version

by ultranerds (Friar)
on Nov 05, 2008 at 16:50 UTC ( #721721=perlquestion: print w/replies, xml ) Need Help??
ultranerds has asked for the wisdom of the Perl Monks concerning the following question:


I'm writing a script ATM, which will print out the Perl and Apache version. Now, getting the Perl version is simple - $]

However, the Apache version is prooving much harder.

I'm guessing something like:

`/usr/bin/httpd -v`

...but this needs to work on a LOT of servers (mainly UNIX, but possibly NT servers too).

Anyone got any suggestions?



Replies are listed 'Best First'.
Re: Getting Apache Version
by pjotrik (Friar) on Nov 05, 2008 at 17:42 UTC
    With mod_perl 2, Apache version can be obtained with Apache2::ServerUtil::get_server_version();

      Thanks - this needs to be compatible will servers that don't have mod_perl/mod_perl 2 at all :( (just basic servers really)


        Have you asked apache?
Re: Getting Apache Version
by Taulmarill (Deacon) on Nov 05, 2008 at 17:02 UTC
    If you're using CGI, the enviroment variable SERVER_SIGNATURE gives you information about the webserver you're running.

      Thanks for the reply.


      SERVER_SOFTWARE ---> Apache

      ..and SERVER_SIGNATURE doesn't seem to exist.

      Any other ideas? :)


        Oh sorry -just realized I wasn't too clear :) I need the actual version of Apache.

        Basically, its a service we are offering to clients - which shows a "badge" for sites using the latest versions (stable) of Perl/PHP/Apache.


Re: Getting Apache Version
by b10m (Vicar) on Nov 06, 2008 at 08:44 UTC

    I'd probably first scan the machine for apachectl or apache2ctl and when found, launch it with a '-v' flag. That'll show you information like (two random test servers):

    $ apachectl -v
    Server version: Apache/2.2.4 (FreeBSD)
    Server built:   May 18 2008 17:19:41


    $ apache2ctl -v
    Server version: Apache/2.2.3
    Server built:   Mar 22 2008 09:29:10

    Easy enough to parse that, I assume ;-)

      Hi, Thanks for the reply guys. From the sounds of it, there is no "simple" way of doing this. I think the approach I'm gonna take is putting some examples in "comments" inside the script, so they can test the different paths themselves (and if needed, as their host). So something like:
      my $path = 'apachectl'; my $output = `$path -v`; my @split = split /:/, $output; if ($split[1] !~ /\d\.\d\.\d/) { print qq|Cant find Apache version <br />|; } else { print qq|$split[1] <br />|; }
      Thanks guys. Andy
      Damn it - won't work :(
      #!/usr/bin/perl # example paths can be: # apachectl # apache2ctl # httpd my $path = 'httpd'; print "Content-Type: text/html \n\n"; print "Perl: " . $] . "<br />"; my $output = `$path -v`; my $output2 = system(qq|$path -v|); print "OUTPUT: ($path -v) " . $output . "<br />"; print "OUTPUT 2: ($path -v, as system()) " . $output2 . "<br />"; my @split = split /:/, $output; if ($split[1] !~ /\d\.\d\.\d/) { print qq|Cant find Apache version <br />|; } else { print qq|$split[1] <br />|; }
      ..yet all that gives is:
      Perl: 5.008004 OUTPUT: (httpd -v) OUTPUT 2: (httpd -v, as system()) -1 Cant find Apache version
      Seems that it doesn't like giving the results with `` or system(). Any suggestions? TIA Andy
        Anyone got any suggestions? :/


Re: Getting Apache Version
by Taulmarill (Deacon) on Nov 05, 2008 at 17:03 UTC
    If you're using CGI, the enviroment variables SERVER_SIGNATURE and SERVER_SOFTWARE give you information about the webserver you're running.
      Unless they run servers with something like ServerTokens Prod directive. Then the version number can be obtained via mod_perl as described in Apache2::ServerUtil documentation.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://721721]
Approved by Limbic~Region
[marto]: Corion worse, some plant inspection, cameras moving thru pipes
[marto]: Discipulus yeah, just don't adopt his tactics :P
[marto]: the content for the most part is fairly dull, but if they go for it, they can use it for all sorts of video, they have no solution for this at the moment
[Discipulus]: with "thru pipes" you mean bot cameras moving inside pipes?!?

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (8)
As of 2017-07-28 09:29 GMT
Find Nodes?
    Voting Booth?
    I came, I saw, I ...

    Results (425 votes). Check out past polls.