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.
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.
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);
?>error_reporting(E_ALL); – Tells PHP to report all types of errors, warnings, and notices.
ini_set('display_errors', 1); – Ensures errors are displayed (or logged) for debugging purposes.
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_logFor errors in subdirectories, the log file will appear in that folder (e.g., /wp-admin/error_log for WordPress admin errors).
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.