Improve company productivity with a Business Account.Sign Up


send email on php or mysql error, server wide

Posted on 2007-11-16
Medium Priority
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
  • 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 300 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.
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.


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 300 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 900 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

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Laravel is the most sought after web development framework. It comes with ample amount of features that make it easy for developers to work around it. Know about its features in detail.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

607 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