How do I configure PHP and nginx to display errors only for specific IP addresses?
1 Answer
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');
}
5 Comments
zerkms
Some sort of errors like Fatal still wouldn't be visible for that ip
Ezequiel Muns
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.
zerkms
I'd agree, yes, but I still think that this is not acceptable for production
Ezequiel Muns
I'm with you on that, though sometimes you do find heisenbugs that only appear in production. Logging is indeed the answer.
zerkms
@Sorin Sbarnea: I have left comments, doesn't worth separated answer ;-)