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 Fatal Errors Log
WooCommerce 3.2 introduced a log that displays PHP fatal errors. This log can contain pertinent information that would be found in the PHP error logs. It is a good place to start before moving to finding the PHP logs on the server.
To access the WooCommerce Fatal Errors log:
- Go to WooCommerce > Status > Logs
- Choose a log from the drop-down labeled
fatal-errors.log
- Click View
Example log:
The types of errors caught in this 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
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, callederror.log
- in
var/logs
or similar, callederror.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 calleddebug.log
If you’re having trouble finding the file, you can have PHP tell you where it is:
- Create a file named
phpinfo.php
in the root of your WordPress’s directory - Open the
phpinfo.php
file in a text editor - Insert the following code into the file:
<?php phpinfo(); ?>
- Open the file on your site. For example, if your site’s URL is
example.com
, you can open the file by visitinghttp://example.com/phpinfo.php
- 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: