Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have some server applications running on apache2; Ruby on Rails, PHP and others.

In all cases I would like apache to send me an email whenever apache responds a HTTP error 500 Internal server error.

How can I do that?

share|improve this question
Are you running Linux? – quanta Aug 31 '12 at 5:57
Yes. I would expect that that did not affect the answer. – Jarl Aug 31 '12 at 6:02
possible duplicate of Linux monitor logs and email alerts? – quanta Aug 31 '12 at 6:06
Why do you tag this with linux? The question is not linux specific – Jarl Aug 31 '12 at 6:16
@quanta: Thanks for pointing me to Linux specific workarounds if no one can answer this question. However I do not consider the question a duplicate. – Jarl Aug 31 '12 at 6:26

You can create a custom 500 file. Assuming you are using Apache you would add the following line to your .htaccess

ErrorDocument 500 /errorfilename.php

This code basically tells the server that if a user encounters a 500(internal server error) Error to display errorfilename.php.

In this PHP file you can add code to email you when a user gets to the 500.

//this is the 500 error php file
mail(,500 error encountered,'message here');
500 internal server error
The administrator has been notified
<a href="index.php">Go to Homepage</a>
share|improve this answer

You can use the ErrorDocument directive to deliver a custom error message, and make that file a script that sends the e-mail. Alternatively, write the error page so that it writes a file with whatever information you want and set up a cron job to mail these files to you.

share|improve this answer
Thanks for an excellent workaround. However the applications all have some custom pages for error 500. A typical rails application have a file public/500.html that is shown upon an internal server error. Your proposal would interfere with these application specific error documents. – Jarl Aug 31 '12 at 6:52

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.