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

Getting Apache Version

by ultranerds (Hermit)
on Nov 05, 2008 at 16:50 UTC ( [id://721721]=perlquestion: print w/replies, xml ) Need Help??

ultranerds has asked for the wisdom of the Perl Monks concerning the following question:

Hi,

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?

TIA!

Andy

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();
      Hi,

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

      TIA

      Andy
        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.
      Hi,

      Thanks for the reply.

      However:

      SERVER_SOFTWARE ---> Apache

      ..and SERVER_SIGNATURE doesn't seem to exist.

      Any other ideas? :)

      TIA

      Andy
        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.

        TIA

        Andy
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

    and

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

    Easy enough to parse that, I assume ;-)

    --
    b10m
      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? :/

        Cheers

        Andy
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?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://721721]
Approved by Limbic~Region
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (3)
As of 2024-03-19 07:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found