How to Log PHP Errors and Warnings

You don’t want to keep the debug mode enabled to display the errors and warnings on your website but still want to see what you’re missing? Or maybe just want to write some info to a log for debugging purposes?

Then… enable the PHP log:

<?php
ini_set("log_errors", 1);
ini_set("error_log", "php.log");
?>

I set the filename to php.log which will write the log in the website’s directory. You can also use something like /tmp/php.log. Your choice…

Now let’s write something to the log from a php page:

<?php
error_log( "This is my important message for the log :)" );
?>

Leave a Reply

Your email address will not be published. Required fields are marked *