When submitting a support request for a WordPress plugin, one of the first things that will typically be asked for is the contents of your site’s PHP error log. The error log provides a ton of useful information about plugin conflicts or PHP version issues which can help whoever is troubleshooting either rule out or narrow down the issue.
WordPress makes retrieving and/or sharing your PHP error logs straight-forward and once you know how you’ll probably start using it to troubleshoot on your own.
Enabling the WordPress Debug Log
The WordPress error log is controlled by a couple of WP PHP constants.
WP_DEBUG
WP_DEBUG_LOG
Nearly all WordPress constants are intended to be defined in a “wp-config.php” file at the root of your site. In order to add the constants you’ll need to edit the wp-config.php file using your favorite editor or FTP.
Some hosts will include file editors on their server. If file editing is available, the hosts documentation will provide instructions on how to edit files.
Once you have the wp-config.php file open to edit, the first thing to check is if the constants WP_DEBUG
or WP_DEBUG_LOG
is already present. If they are, you must replace the existing WP_DEBUG
and WP_DEBUG_LOG
constants instead of adding new ones or your site will throw an error.
Add or replace the constants with the following values.
Save the file to your server and the WordPress debug log is now available.
Viewing and sharing the log
With the WordPress debug log active, a debug.log
file is updated with all the information from the PHP error log and made available in the content directory of your site.
For example, if your site is located at “https://example.com” the debug.log would be available at “https://example.com/wp-content/debug.log.”
You may view the log yourself and/or provide the link of debug.log to the support ticket requesting the contents of your PHP error log.
Viewing PHP errors on your site
Sometimes it can be useful for debugging to see the PHP errors on your site where they are being generated. For example, you may see an error in the log and not be sure where on site the error is happening.
If you prefer to see the results of your PHP errors, you can use a third WP constant to turn on displaying of errors.
Like the other 2 WP constants, be sure to replace the WP_DEBUG_DISPLAY
constant instead of adding a new one if the WP_DEBUG_DISPLAY
constant already exists.
Using the Native PHP Error Log
If you are not using WordPress or prefer not to add constants to your wp-config.php file, you can still retrieve the contents of the error log built natively into your PHP server.
Some hosts will include log viewers in their portal or provide New Relic access to view logs. If these options are available with your host, the hosts documentation will provide instructions on how to view the logs.
Each server will store the PHP error logs in a different location. There are a couple of ways to retrieve the location of the error logs.
Using a terminal
If you have access to a terminal to your server using SSH or really any other way you can open a terminal will do.
- Open a terminal.
- Run the command
php -i | grep "error_log"
- Make note of the
error_log
line.- An example result could be “error_log => /var/logs/php_error.log => /var/logs/php_error.log”
In this example, the location of the error log file is “/var/logs/php_error.log.” Open the file using your favorite file editor or FTP and you have the contents of your PHP error log.
Using the phpinfo() function
If you have access to files on your site, you can retrieve the location of the PHP error log by creating a custom .php
file and adding the phpinfo()
function to it.
- Create a new
info.php
file in the root of your site. - Add the following contents to the file.
Now going to the file in your browser will provide a lot of information on your PHP installation. If your site is located at “https://example.com” you would open a browser and go to “https://example.com/info.php.”
Search for the word “error_log” in the shown contents. The value will be the location of your PHP error log. Open the file using your favorite file editor or FTP and you have the contents of your PHP error log.
Note: When you are finished retrieving the error log location, you’ll want to remove the “info.php” to prevent exposing PHP information to the public.
Further
WordPress Developer Resources has a ton of information on various debugging techniques similar to what we’ve covered in this article.