send email on php or mysql error, server wide

Posted on 2007-11-16
Last Modified: 2012-05-05
I run an apache 1.3 cpanel server centOS, php 5 mysql 5.
I am running php suexec
I am trying to set up error logging to email me every time a php error is encountered, instead of just logging it to a file
Currently errors are logged localy (the folder the script is in)
As a start, I have set error_log= /var/log/php/php_error_log in php.ini
No errors are being logged to this file though.
I have set permissions to -rw-r--r--    1 nobody   root  (I also tried root:root)
I am concerned it might be a file ownership problem.  I have read the log file needs to be owned by the same owner as the script that generates the error.  If so, then would it be impossible to have all php errors on the server log to the same file (many different accounts)?
If so, is there a way around this?

Anyway, back to what I am trying to accomplish: emailing me every time there is a php or mysql error.
Is this possible, and could I get some pointers on how to set it up.
I have googled this quite a bit, with not much luck.  The best info I found was here:
But I still couldnt find exactly what I was looking for.

Also, if possible it would be nice if I could specify that it would email only on certain errors, or types of errors.
What I am most interested is mysql errors, but basically all fatal php errors.

The idea is to have all visual error reporting off, so no errors are displayed to the web page, but to be sent an email every time an error occurs.

If possible, it would be fantastic if this email could be customized, to perhaps contain some custom info like perhaps the query that failed, or the page and line number that casued the error, and especially to have the account name in the email, or better yet the subject line.

I currently have done this on a per site basis for many sites, using php error handling in the scripts on the site, but what I want to know, is is it possible to configure this server wide.


Question by:tkerns
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
  • 2
  • +1
LVL 48

Expert Comment

ID: 20296826
The Zend Platform is AFAIK capable of the most things you wanted. Check out

Author Comment

ID: 20296863
Unfortunately the zend platform is well above my price range.  I am hoping to find something I can do with my current platform.


LVL 21

Assisted Solution

nizsmo earned 100 total points
ID: 20296941
To turn error reporting off:

also in the php.ini there is this setting:
display_errors = Off/On

you can set this to off to turn the errors off.

Not too sure about emailing the errors though.
How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.


Author Comment

ID: 20296980
Display errors is off, and no errors are displaying.
when I had  error_log= error_log in php.ini, it would log locally to an error_log file in the same directory as the script, but when I set error_log=/var/log/php/php_error_log then it stopped logging.
LVL 48

Assisted Solution

hernst42 earned 100 total points
ID: 20296990
make sure /var/log/php/php_error_log is owned by the webserver user, so php can write the logs there. THis eorks unless you are using something like suExex or suPHP

Author Comment

ID: 20300071
Actually, as I mentioned in my original question, /var/log/php/php_error_log is owned by nobody:root,
but that I  am running suexec, so php runs as a user, and is there any away around the owner issue, and get the log to write to that file, or better yet, email me.
LVL 57

Accepted Solution

giltjr earned 300 total points
ID: 20522661
If you are using suexec and have the scripts executed under different user id's, then you need to set the permission on the log file so that anybody can write to it, so I would suggest setting it to 777.

Now, I will need to research a little more about the e-mail.  Would it be O.K. to e-mail you once a day with all of the errors up to that point in time, or do you really need the email sent as soon as the error occurs?
LVL 57

Expert Comment

ID: 20522702
Of couse you could also create a group and put all of the userid that you execute the PHP scripts in that group and give the group write access.  That way you only need 764 which is a bit more secure.

Author Comment

ID: 20523469
Thanks for the input.  I had almost given up on this.  
I will give that a try.  I really do need the error sent as soon as it happens, instead of daily.
Currently I have an error handler custom written for each site (userid) and I am trying to avoid that.

I am not sure how to set up a group like you mentioned, but I will do some research.

LVL 57

Expert Comment

ID: 20525214
Most distributions have the group "users".  As root you can do "grep users /etc/group" and see if you have that one.

If you have the group users, then (again as root) you can do:

   usermod -G users xxxx

where xxxx is each user you want to add to the group users.  Then you can make the owner of the file nobody:users and the permissions 764.

I still need to look at the automated instant email part.


Author Comment

ID: 20669727
Thanks everybody for the help.
I am still catching up from the holidays.  I have been unable to get this to work, and it appears that it is more difficult than I though, if not impossible.
Everybody gets points for helping!
I think giltjr is on the right track tho, and that option is the one I have been persuing.

For the time being, I will be sticking with my current scheme, which includes a custom error handler included on every php page, that emails me if there is a problem.
Thanks again.


Featured Post

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
This article discusses how to create an extensible mechanism for linked drop downs.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question