1. Documentation /
  2. Finding PHP Error Logs

Finding PHP Error Logs

With WordPress and WooCommerce, PHP error logs can be useful when investigating an issue with a site. This guide will provide steps and information about accessing the PHP error logs either within WooCommerce or on a hosting server.

WooCommerce Logger

↑ Back to top

WooCommerce features a logging system accessible via WooCommerce > Status > Logs, which records PHP fatal errors among other pertinent information.

This log serves as a valuable initial resource, mirroring details that would typically be found in the PHP error logs on the server. It is recommended to consult this log first before proceeding to locate the PHP logs on the server for further troubleshooting.

With WooCommerce 8.6, we have revamped the logging system to enhance its utility for all users. This concentrates on the filesystem method of storing logs (as opposed to the database method). A major enhancement includes a new interface that simplifies the process of browsing and viewing log entries.

Log File Browser

↑ Back to top

To access the log files:

  1. Navigate to WooCommerce > Status > Logs
  2. On the “Browse Log Files” screen, you will see a list of available log files.
Log File Browser

The “Browse Log Files” interface allows you to filter, sort, and manage log files efficiently. Additionally, you can perform bulk actions, such as downloading or deleting multiple log files simultaneously, by selecting the desired files and utilizing the bulk action dropdown menu.

Downloading Log Files in Bulk

If you are using WooCommerce versions before 8.6, you can access log files by navigating to WooCommerce > Status > Logs. Here, select a log file from the drop-down menu located in the top-right corner of the screen.

We highly recommend upgrading to the latest version of WooCommerce to take advantage of new features, such as the improved WooCommerce Logger interface. Regular updates of WordPress and all associated plugins are crucial for the seamless functioning of your website.

Searching Logs

↑ Back to top

You can now choose a group of files for targeted searches by employing filtering and sorting methods. Subsequently, you can link directly to specific lines within those files that contain the relevant results.

Searching within Log Files

Single file viewer

↑ Back to top

This view presents the content of an individual log file, highlighting the start of new entries and their severity levels. It enables users to highlight and create permalinks for specific lines within a file, as well as to display extra contextual information for each log entry in a clear and readable format.

On this screen, you have the option to either download or delete the log file, using the buttons located at the top of the file viewing interface.

Single file viewer

Settings

↑ Back to top

The settings for managing log files can be adjusted via the settings page, found at WooCommerce > Status > Logs > Settings. The configurable options include:

  1. Logger: This option allows you to activate or deactivate logging.
  2. Log Storage: Determines the location where log entries are stored. By default, “File System” is selected. An alternative option is “Database,” which is not recommended to be used on live sites. It’s important to note that changing this setting will not move existing log entries; they will stay in their original location.
  3. Retention Period: Defines the duration (in days) that log entries will be retained before automatic deletion. The default setting is 30 days.
  4. Level Threshold: Specifies the minimum severity level for logs to be recorded, with lower severity levels being omitted. The default setting is “None,” indicating that all logs are stored. Options include Alert, Emergency, Debug, Critical, Error, Warning, Notice, None, and Info.
  5. File System Settings: This specifies the server location where log files are stored (e.g., /srv/htdocs/wp-content/uploads/wc-logs/). You have the option to modify this location by setting the WC_LOG_DIR constant in your wp-config.php file to a new path.
WooCommerce Logger Settings

Fatal Errors

↑ Back to top

To access the fatal errors:

  1. Navigate to WooCommerce > Status > Logs
  2. On the “Browse Log Files” screen, click on the file named “fatal-errors” to open and view its contents.

The types of errors caught in the “fatal-error” log are PHP fatal errors, runtime errors, and errors purposely triggered in the code by a PHP function. Runtime errors can occur when there is a typo in the code, for example.

Fatal errors occur when the action in the code cannot be completed. Examples of a fatal error include:

  • Calling an undefined function
  • Using an undefined variable
  • Calling a function on a null or otherwise unusable variable

This does not include web server errors, such as timeouts.

The log will include the:

  • Timestamp when the error occurred
  • Error that occurred
  • File and line in the code for the origination of the error
  • Stack trace – a snapshot of the history of the function calls and files leading up to the error

PHP Error Logs on the Server

↑ Back to top

You can find the PHP error logs in a few possible places on the server:

  • in your server’s root folder, called error.log
  • in public_html or similar folder, called error.log
  • in var/logs or similar, called error.log
  • additionally, if you have debugging enabled in WordPress and you have it saved to a file, it will be in the wp-content folder, and called debug.log

If you’re having trouble finding the file, you can have PHP tell you where it is:

  1. Create a file named phpinfo.php in the root of your WordPress’s directory
  2. Open the phpinfo.php file in a text editor
  3. Insert the following code into the file: <?php phpinfo(); ?>
  4. Open the file on your site. For example, if your site’s URL is example.com, you can open the file by visiting http://example.com/phpinfo.php
  5. Search the page for the error_log value. The file path listed here is the absolute file path of the PHP error log – visit that address on your server and you should find the PHP error log. If the value is empty, then you need to set a value to log errors on your site. See the picture below for how it should look like:
Example PHP Info Output