How to configure apache to send email with every HTTP 500 error

I have server applications running on apache2; Ruby on Rails, PHP and others.

In all cases, I would like apache to send me an email when apache responds to an HTTP 500 error. Internal server error.

How can i do this?

+5
source share
3 answers

Cannot configure apache to send emails.

There are several things you can do to achieve the same result:

+10

- php script, , - 500 . ErrorDocument:

ErrorDocument 500 /path/to/script/that/sends/email.php
+9

script log_monitor.sh:

#!/usr/bin/perl -w

use strict;

my $cachefile="/var/cache/lastpos-apache2-scan4maxclntOrSigKill";
my $logfile="/var/log/httpd/error_log";
my $searchstr=" 500 ";

my $lastpos=0;
if (-f $cachefile) {
    open FH,"<".$cachefile;
    $lastpos=<FH>;
    close FH;
};

my $newpos=(stat $logfile)[7];

open FH,"<".$logfile;
seek FH,$lastpos,0;
while (<FH>) {
    print if m/$searchstr/i;
};
close FH;

open FH,">".$cachefile;
print FH $newpos;
close FH;

$searchstr . "500", , 404 , "500" ( ).

script X cron. X, ( 1 X , , ). cron ( cron )

+4

All Articles