?
Solved

send email on php or mysql error, server wide

Posted on 2007-11-16
11
Medium Priority
?
206 Views
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:
http://www.php.net/errorfunc
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.

Thanks!

Tom
0
Comment
Question by:tkerns
[X]
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
11 Comments
 
LVL 48

Expert Comment

by:hernst42
ID: 20296826
The Zend Platform is AFAIK capable of the most things you wanted. Check out http://www.zend.com/products/zend_platform
0
 

Author Comment

by:tkerns
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.

Thanks.

Tom
0
 
LVL 21

Assisted Solution

by:nizsmo
nizsmo earned 300 total points
ID: 20296941
To turn error reporting off:
error_reporting(0);

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.
0
Limited time offer using promo code EXPERTS25

Designed with a wealth of functionality and convenience, ATEN's new Thunderbolt™ 2 Sharing Switch takes your Thunderbolt setup to the next level. Now through August 31, 2017, Experts Exchange members get 25% off the US7220 on the ATEN USA eShop using promo code EXPERTS25.

 

Author Comment

by:tkerns
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.
0
 
LVL 48

Assisted Solution

by:hernst42
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
0
 

Author Comment

by:tkerns
ID: 20300071
hernst,
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.
0
 
LVL 57

Accepted Solution

by:
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?
0
 
LVL 57

Expert Comment

by:giltjr
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.
0
 

Author Comment

by:tkerns
ID: 20523469
Hi,
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.

Thanks
0
 
LVL 57

Expert Comment

by:giltjr
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.

     
0
 

Author Comment

by:tkerns
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.

Tom
0

Featured Post

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

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

It is possible to boost certain documents at query time in Solr. Query time boosting can be a powerful resource for finding the most relevant and "best" content. Of course the more information you index, the more fields you will be able to use for y…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

770 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