Awstats with apache2 + mod_perl

2005-01-24
2013-03-04
  • Is it possible to use awstats with mod_perl and apache2? Is there anything you need to modify?

    Is there anything i would need to do to make this work?

     
  • wizsilex
    wizsilex
    2012-01-11

    Get mod_perl for apache2:

    apt-get install libapache2-mod-perl2
    

    make dir /usr/local/lib/site_perl/Filters/:

    mkdir  /usr/local/lib/site_perl/Filters/
    

    make Perl Filer Module /usr/local/lib/site_perl/Filters/Awstats.pm:

    package Filters::Awstats;
    ## Wizsilex.com - 2012/01/11
    
    use strict;
    
    use Apache2::Filter ();
    use Apache2::Const -compile => qw(OK OR_ALL NO_ARGS);
    use Apache2::Module ();
    use Apache2::CmdParms;
    use Apache2::RequestRec ();
    use APR::Table;
    
    use constant BUFF_LEN => 8000;
    
    sub handler {
        my $f = shift;
    
        unless ($f->ctx) {
            $f->r->headers_out->unset('Content-Length');
            $f->ctx(1);
        }
    
        while ($f->read(my $buffer, BUFF_LEN)) {
            my $cfg = Apache2::Module::get_config(__PACKAGE__, $f->r->server);
    
            my $awstats_in = "</body>";
            my $awstats_out = "";
    
                $awstats_out = <<EOF;
    <script src="/js/awstats_misc_tracker.js" type="text/javascript"></script>
    
    </body>
    EOF
    
            chomp $awstats_out;
    
            if ($buffer =~ m|</body>|i) {
                unless ($buffer =~ m/("awstats_misc_tracker")/) {
                    $buffer =~ s/$awstats_in/$awstats_out/i;
                }
            }
    
        $f->print($buffer); # write to the outgoing brigade
        }
    
        return Apache2::Const::OK;
    }
    
    ###
    1;#
    ###
    

    Add to apache default conf /etc/apache2/sites-available/default inside
    <VirtualHost> i add i just before </VirtualHost>

    PerlLoadModule Filters::Awstats
    <Files index.php>
    PerlOutputFilterHandler Filters::Awstats
    </Files>
    

    Make sure you have file awstats_misc_tracker.js in /js/ folder in root for
    webserver