How to Access the PHP Error Log

TL;DR
To access the PHP error log on your WordPress site:

  1. Check if your hosting provider offers a log viewer in its control panel.
  2. Locate the log file on the server, usually found in /var/log/, /logs/, or your site’s root folder.
  3. Enable logging in wp-config.php if it’s not already active.
  4. Use a logging plugin if you prefer a WordPress dashboard interface.

Introduction

When troubleshooting issues with your WordPress site, the PHP error log is a crucial resource. It provides detailed insights into errors, warnings, and notices generated by your site’s PHP code. This is especially helpful when debugging issues that might arise from plugins, themes, or custom code.

In this article, you’ll learn different methods to locate and access the PHP error log for your WordPress installation.


Method 1: Access Through Your Hosting Provider

Most hosting providers include an error log viewer in their control panel.

Steps:

  1. Log in to your hosting control panel (e.g., cPanel, Plesk, or a custom dashboard).
  2. Navigate to the Logs section (or similar).
  3. Look for an option like PHP Error Log or Error Logs.
  4. Open the log file and inspect the entries for issues.

Pros:

  • Easy to use for non-technical users.
  • Centralized logging for multiple services.

Cons:

  • Limited to what the hosting provider exposes.

Method 2: Locate the PHP Error Log File

If your hosting provider doesn’t offer a viewer, you can usually manually find the log file on your server.

Common File Locations:

  • /var/log/php_errors.log
  • /logs/ folder in your hosting account.
  • error_log file in your WordPress root directory.

Steps:

  1. Connect to your server using an FTP client or file manager.
  2. Look for common error log locations.
  3. If you can’t find the log, contact your hosting support team for guidance.

Method 3: Enable Debug Logging in wp-config.php

If the PHP error log isn’t enabled, you can turn on WordPress-specific debugging.

Steps:

  • Edit your wp-config.php file using an FTP client or hosting file manager.
  • Add or update the following lines:
define('WP_DEBUG', true);
define('WP_DEBUG_LOG', true);
define('WP_DEBUG_DISPLAY', false); // Errors will not display on-screen
  • Save the file.
  • Access the log at wp-content/debug.log.

Method 4: Use a Logging Plugin

If you prefer accessing logs directly from your WordPress dashboard, use a free logging plugin like Query Monitor: https://wordpress.org/plugins/query-monitor/. Alternatively you can use Error Log Monitor or WP Debugging.

Steps:

  1. Install and activate the logging plugin of your choice.
  2. Configure the plugin settings to enable or view logs.
  3. Access logs from the plugin interface within your dashboard.

Pros:

  • No need to access the server or hosting panel.
  • Convenient for non-technical users.

Best Practices for Using PHP Error Logs

  • Secure Logs: Restrict access to your error logs to avoid exposing sensitive information.
  • Regular Maintenance: Periodically review and clear error logs to manage disk space.
  • Disable Debugging in Production: Always turn off debugging options in wp-config.php on live sites:
define('WP_DEBUG', false);

Conclusion

Accessing the PHP error log is a straightforward yet powerful way to debug WordPress issues. Whether you rely on your hosting control panel, locate the log file manually, or enable debugging via WordPress, the error log is an invaluable tool for maintaining a healthy site.