Solved

send email on php or mysql error, server wide

Posted on 2007-11-16
11
202 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
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 

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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
what is best version of php to use 6 44
.php tree directory? 5 55
MySQL Grouping 2 21
How to convert my query to the proper format? 5 16
In Solr 4.0 it is possible to atomically (or partially) update individual fields in a document. This article will show the operations possible for atomic updating as well as setting up your Solr instance to be able to perform the actions. One major …
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
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…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

914 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

19 Experts available now in Live!

Get 1:1 Help Now