0

How do I configure PHP and nginx to display errors only for specific IP addresses?

1
  • 1
    Why not to log everything instead? Displaying errors is never a good idea on production servers Commented May 10, 2012 at 0:25

1 Answer 1

3

You could first set PHP to not display errors at all (display_errors = Off in php.ini), then use the auto_prepend_file directive in your php.ini to include this script:

<?php
$allowed_ips = array('111.111.111.111', ...);
if (in_array($_SERVER['REMOTE_ADDR'], $allowed_ips)) {
    ini_set('display_errors', '1');
}
Sign up to request clarification or add additional context in comments.

5 Comments

Some sort of errors like Fatal still wouldn't be visible for that ip
Yes, it's true. Though I wonder, since this would be the very first thing that runs, only parse errors and static includes not found would remain invisible. Would you agree? I don't actually know the PHP execution lifecycle that well.
I'd agree, yes, but I still think that this is not acceptable for production
I'm with you on that, though sometimes you do find heisenbugs that only appear in production. Logging is indeed the answer.
@Sorin Sbarnea: I have left comments, doesn't worth separated answer ;-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.