Solved

send email on php or mysql error, server wide

Posted on 2007-11-16
11
201 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
  • 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 100 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
 

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 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
0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 

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 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?
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

If your site has a few sections that need to be secure when data is transmitted between the server and local computer, such as a /order/ section for ordering or /customer/ which contains customer data, etc it would of course be recommended to secure…
This article discusses how to create an extensible mechanism for linked drop downs.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
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.

707 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now