Page 1 of 1

How do I get PHP errors to display?

Posted: Sun May 06, 2018 11:37 pm
by nathanjame
I have checked my PHP ini file and display errors is set and also error reporting is E_ALL. I have restarted my Apache web server.

I have even put these lines at the top of my script, and it doesn't even catch simple parse errors. For example, I declare variables with a "$" and I don't close statements";". But all my scripts show a blank page on these errors, but I want to actually see the errors in my browser output.

error_reporting(E_ALL);
ini_set('display_errors', 1);

What is left to do?

Re: How do I get PHP errors to display?

Posted: Mon May 07, 2018 5:49 pm
by protopatterns
Go about it systematically:

First, make sure you are using the correct php.ini. PHP usually ends up giving you all sorts of php.ini, but the only one you should be worried about is the one which is linked to your Apache server.

I assume this is just on localhost, not a live site. Are you using Linux or Win? (..or maybe a Mac?) On Win if you're using WAMP, I remember the correct .ini file (that's hooked to Apache) is somewhere in the WAMP tray. If you're using Ubuntu the right one's here: /etc/php/7.0/apache2/php.ini (at least on my machine).

Go into the the ini file, do a search for and set these 4 directives:

Code: Select all

error_reporting = E_ALL
display_errors = On
log_errors = On
;           No quotes:
error_log = /whatever/dir/you/prefer/php_errors.log
Restart your Apache.

Then, for the sake of redundancy (these will override your php.ini directives), put these 4 functions at the top of your script:

Code: Select all

ini_set("display_errors", "1");
ini_set("log_errors", "1");
ini_set("error_log", "/whatever/dir/you/prefer/php_errors.log");
error_reporting(E_ALL);
If this is working, you can figure out what's making it work through process of elimination, e.g., if it stops working when you comment out the ini_set("display_errors", "1") function, then you know you have the wrong php.ini file, etc.

Re: How do I get PHP errors to display?

Posted: Wed May 09, 2018 9:54 am
by protopatterns
..Or you could do it the easy way :)

Code: Select all

phpinfo(); 
This function gives you 'Loaded Configuration File', among others.

And you can always overwrite your php.ini settings per-directory:

https://blog.arvixe.com/setting-custom- ... r-website/