Reputation: 6375
I am running PHP and nginx and I use a production version of php.ini. So the variable display_error is set to Off and there is a good reason I want it this way. But for certain files I need to enable error reporting. I used ini_set to turn on error reporting. But a simple code snippet like:
<?php
error_reporting(E_ALL);
ini_set("display_errors", 1);
echo "hi"errorrrrr
?>
does not trace the error. It simply returns a HTTP 500 Internal Server Error message. What should I do to enable error reporting?
Upvotes: 3
Views: 2528
Reputation: 6375
The answer I was looking for is in the comments of this answer: PHP does not return errors at all
The reason it doesn't work in the first place is that, since there are syntax errors in your file, PHP does not parse it at all. Thus, it doesn't execute the log_errors calls and has to rely on the settings in php.ini.
– cmptrgeekken Mar 16 '10 at 18:16
Upvotes: -1
Reputation: 31813
If you simply can't change the configuration of php, there's a trick you can do. Make a new file which includes the file with the error in it. Before doing the include, set the desired configuration.
Example
error_reporting(E_ALL);
ini_set("display_errors", 1);
include 'some other file with a parse error.php';
Then just execute the wrapper script instead. This works because the statements preceding the include will be evaluated first, before your script finally dies from the parse error.
Upvotes: 1
Reputation: 10892
Try setting the ini settings in a .htaccess
file.
The settings won't take hold if you put them in a PHP file that doesn't get compiled due to a syntax error in the first place.
Upvotes: 1
Reputation: 157839
Of course PHP won't execute these directives if syntax error occurred. Because this script didn't even start to execute! As it failed at parsing phase.
You have to use another way to set these directives, although it can be tricky. Looks like you have your PHP running as CGI, not apache module, so, the only way to set ini directives is to edit php.ini itself.
To be sure, please run phpinfo();
and see what it says of Server API.
Anyway, you have to check apache's error_log every time you see 500 error, to find out what certainly happened.
Upvotes: 1
Reputation: 134167
You should be able to use log_errors
to log all of your errors to file. You can even use error_log
to write errors to a specific file, if that will make life easier for you.
Upvotes: 1