Awstats with apache2 + mod_perl

  • Nobody/Anonymous

    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/

    package Filters::Awstats;
    ## - 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) {
        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>
            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;

    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

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


Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.

No, thanks