2

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?

Jarl
  • 305
  • 1
  • 4
  • 9

2 Answers2

4

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.

<?php
//this is the 500 error php file
mail(ma@me.com,500 error encountered,'message here');
?>
<html>
<head>
<title>500</title>
<body>
500 internal server error
The administrator has been notified
<a href="index.php">Go to Homepage</a>
</body>
</html>
Bortix
  • 83
  • 6
1

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.

Christian
  • 110
  • 1
  • 4
  • 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 06:52