phperrlog – Monitor and consolidate php and apache error logs on the server

One of the prerequisites of a successful site is making sure everything is running as it should. When you have a lot of sites to take care of, tracking the problems can be really time consuming.

Especially I was lacking reporting on PHP errors produced by various sites. So I wrote this bash script which purpose is to once a day send you an email with all errors happening on all your sites on the server.


# phperrlog v1.0
# by vladimir prelovac
# parse error logs on your server and send you daily updates to email

# configure options
EMAIL=enter email here

TAIL=5  # number of entries to send
IGNORE="/backup" # path to ignore

# script starts 'ere

rm phperrlog.txt

LIST=`locate error_log  | grep -v $IGNORE`;
today=`date +%Y-%m-%d`

for i in $LIST

if [ -f $i ]; then

  time=`date -r $i +%F`

  if [ "$time" == "$today" ]; then
   echo $i >>phperrlog.txt
   echo "---------------------------------" >>phperrlog.txt
   tail -n $TAIL $i >>phperrlog.txt
   echo -e "\n\n\n\n" >>phperrlog.txt


if [ -f  phperrlog.txt ]; then
  mail -s "server error logs - $today" $EMAIL  < phperrlog.txt


Set the email and other configration options first.

Then, add the script to your cron using, crontab -e. This will start the script every day at 11:55pm

55 23 * * * /root/phperrlog >/dev/null 2>&1

Download link

More like this:

Posted in: SEO, WordPress
TAGS:, , , , , , , , , , , , , , ,
Both comments and trackbacks are currently closed.


  1. g
    Sep 10th, 2012 5:30 AM

    I found that cron always failed the string comparison and never sent an email:

    if [ "$time" == "$today" ];

    So I replaced it with :

    case "$time" in
    "$today" )
    echo $i >>phperrlog.txt
    echo "---------------------------------" >>phperrlog.txt
    tail -n $TAIL $i >>phperrlog.txt
    echo -e "\n\n\n\n" >>phperrlog.txt

  2. gavin
    Feb 3rd, 2012 4:03 AM

    Any thoughts on this?

    ./phperrlog: line 41: mail: command not found

  3. Jan 19th, 2010 11:37 PM

    Maybe try cacti monitoring. Easy to setup, tons of ready to use scripts and template. Integration with system and all components like APC Memcache Mysql apache linux network etc.

    You will be able to monitor your applications as well if you add custom scripts gathering application timers (how much time did it take to call soap service or whatecver)

    this should give you some idea of what kind of graphs can you easily get out of the box.

  4. Rob Smallwood
    Oct 18th, 2009 7:59 PM

    If you're going to use scripting then think about rotating the logs, but reporting a php error is not really good enough.

    You need to monitor your sites as the customer sees them, from the front door. A better approach would be to have a simple monitor page that just responds with 'OK' or something and use nagios to monitor your OK pages. This would at least tell you that your websites are externally visible/don't have connectivity issues and both apache and the underlying application at least work.

    • Oct 19th, 2009 10:17 AM

      I use monitoring tools lke nagios, the script was just an extension to know whats happening inside your websites as no tool that I know of reports php errors.

  5. Oct 16th, 2009 7:44 AM

    I myself, tend to have a centralized location for all my log files, from lighttpd, mysql, php and wordpress, so that I only have 1 location to look at...

    But why cloud up your email?

    Would be nice to have a wordpress plugin, that could look for error log files, and make them readable, in wordpress admin...

    • Oct 16th, 2009 8:13 AM

      What I did however works with non-wordpress sites and allows me greater customization of the output with no alternation of config files. But your solution sounds good, if I knew about the plugin perhaps I wouldn't have dug into this.

  6. greg
    Sep 23rd, 2009 4:45 PM

    This is a great start Vladimir. However, without some basic grouping of error messages like what JakeO Logdigester does, all you get from tail is the last few seconds of errors on a busy server. Our error logs are a problem as well. With a dedicated server and many popular sites it's difficult to separate the garbage from the important errors and warnings. However, combining the errors by message and displaying the list sorted by count of each error message is helpful. Yet, sometimes the most important errors are the rare ones.

    JakeO's php script also doesn't work on standard size apache logs, so you've either got to give it a lot more memory or split your files. It would be nice if someone made a robust solution for monitoring the apache error_log.

    • Sep 23rd, 2009 5:14 PM

      Perhaps a dedicated php script would be better for that, I merely wanted some information about what is going on on the server. JakeO script is good addition and I already modified mine to use it instead for output.

      • Apr 15th, 2010 12:59 PM

        it is usefull, can you tell me which plugin used for code highlight