How to Enable PHP Error Logging in Your Script

Introduction

Sometimes your website may display a blank page or behave unexpectedly. To troubleshoot these issues, enabling PHP error logging is a helpful way to see what’s going wrong behind the scenes.

Procedure

  1. Check for Built-In Options
    Some PHP applications or scripts (like WordPress plugins or themes) include a development or debugging mode. Enabling this mode automatically logs errors to the site’s local error_log file, usually located in the site’s document root.

  2. Enable Error Logging Manually
    If your script does not have a built-in debug mode, you can force PHP to log errors by adding the following lines at the top of your PHP script:

    <?php
    error_reporting(E_ALL);
    ini_set('display_errors', 1);
    ?>
  3. Check the Error Log
    After enabling error logging, any PHP errors will be written to the error_log file in the relevant directory:

    /home/USERNAME/public_html/error_log

    For errors in subdirectories, the log file will appear in that folder (e.g., /wp-admin/error_log for WordPress admin errors).

  4. Troubleshoot Your Script
    Open the error_log file and review the messages. The errors will indicate what’s causing the script to fail so you can take corrective action.