How do I get PHP errors to display?

Ye' old general discussion board. Basically, for everything that isn't covered elsewhere. Come here to shoot the breeze, shoot your mouth off, or whatever suits your fancy.
This forum is not for asking programming related questions.

Moderator: General Moderators

Post Reply
nathanjame
Forum Newbie
Posts: 1
Joined: Sun May 06, 2018 11:34 pm

How do I get PHP errors to display?

Post 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?
protopatterns
Forum Newbie
Posts: 9
Joined: Sun Jan 28, 2018 11:18 am

Re: How do I get PHP errors to display?

Post 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.
protopatterns
Forum Newbie
Posts: 9
Joined: Sun Jan 28, 2018 11:18 am

Re: How do I get PHP errors to display?

Post 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/
Attachments
php-ini.png
Post Reply