How To Check PHP Error Log WordPress

How To Check PHP Error Log WordPress

How To Check PHP Error Log WordPress

Emmanuel Ighosewe
Author
Emmanuel Ighosewe

PHP is the programming language used to create WordPress. When a user requests a web page with PHP code, the PHP module (Apache or Nginx) processes the code on the server. The processing may result in a PHP error. That means there is an issue with the PHP code. Errors can vary; they can be as simple as omitting a semicolon or complicated as calling a wrong variable.

In this article, we will discuss the meaning of PHP error logs, their usefulness, and how you can monitor them using different methods.

What is a PHP Error Log?

A PHP error log list contains warnings and errors resulting from language runtime and is saved in a file. The code used in creating the WordPress is PHP; therefore, it takes care of WordPress errors and logs messages.

There are many reasons for errors. There may be typos in a line of code, or the code may be okay; however, an unexpected event occurred during execution. In any case, the developers want you to be aware of this, so they write code to log the message to a file. The error log is a chronological list of these messages.

The error log is very useful for figuring out why WordPress doesn't work as expected. If it consumes too much server resources, the plugin is corrupted, or the page is not loading, the log will let you know why. If you find yourself in a situation where WordPress doesn't work, logs may be the only way to see what's going on behind the scenes.

How to Check PHP Error Log

There are different ways to monitor PHP Error Log, and some of them include;

  • Using the wp-config.php file
  • Error Logging via the php.ini file
  • Error Logging via the HTAccess file

Method 1: Error Logging using the WordPress configuration (wp-config.php) file

The simplest method to implement PHP error logging on your WordPress site is by adding a few simple lines of code to your wp-config.php file. The WordPress wp-config.php file can be used to set various PHP settings to change the PHP installation functionality. In this way, we leverage this feature through a basic error monitoring implementation on your website. You can follow the following steps:

Step 1: Create a log file

Create a blank file named "PHP-error.log". This file is used as a PHP error log for your Website. It is required that your server has access to this file, therefore ensure permissions are configured appropriately. The file can be placed in any directory, but for security reasons, it is recommended that it be placed in the root directory of your Web site, which is accessible from the Internet. Once you have created and put a writable file in place, note the path of the directory and go to the last step.

Step 2: Adding the code

Then open the configuration file on your website (you will find it in the root WordPress directory) and insert the code below above this line, “That's all, stop editing! Happy blogging.”:

// log PHP errors

@ini_set('log_errors','On'); // enable or disable PHP error logging (use 'On' or 'Off')

@ini_set('display_errors','Off'); // enable or disable public display of errors (use 'On' or 'Off')

@ini_set('error_log','/home/path/logs/php-errors.log'); // path to server-writable log file

After inserting the code, edit the third line with the full directory path of the PHP-error.log file created initially. Upload to your server and access it. All PHP errors are now logged in your PHP-error.log file, so you can monitor and fix errors without wasting time.

Method 2: Log errors via the php.ini file

Suppose you can open the php.ini file of your website or can implement initiation files "by directory". In that case, this method can help you monitor PHP errors for any site, not just those using WordPress technology. The process is almost the same as the previous method and needs the following steps:

Step 1: Create a log file

Same as the first method, create an empty file with the name "PHP-error.log". This file acts as a PHP error log for a website. Your server must be capable of writing this file; therefore, ensure you set proper permissions. You can place the file in any directory; however, to make things safer, it would be best that you position them above the root directory of an accessible site.

Step 2: Add the code

Then, open the php.ini file of the website and enter the code below:

;;; log php errors

display_startup_errors = false

display_errors = false

html_errors = false

log_errors = true

track_errors = true

error_log = /home/path/logs/php-errors.log

error_reporting = E_ALL | E_STRICT

log_errors_max_len = 0

This code is still configured to achieve the best error handling for the production server. All you need to edit is the full path of the log file. During website development, you might need to modify some variables to show errors, startup errors, repeated errors, etc.

Method 3: Log the error via the HTAccess file

Finally, we will see how to enable PHP error logging through the HTAccess. With the HTAccess file enabled on your website, this method is very effective and allows you to log.

PHP errors on any Website, not just those that operate using WordPress.

Step 1: Create a log file

Like we did for other methods, create a blank "PHP-error.log". The file will be a PHP error for your site. Your server must be able to access this file, therefore, set all permissions properly. The file can be on any .directory. Just ensure it is placed above your site's root directory, which is accessible on the web. After creating, saving, and installing this file, note the full directory path and proceed to the last step.

Step 2: Add the magic code

Next, open your site’s root .htaccess file and add the following code:

# log php errors

php_flag display_startup_errors off

php_flag display_errors off

php_flag html_errors off

php_flag log_errors on

php_value error_log /home/path/logs/php-errors.log




If you want Upstack to be part of your story - don't hesitate to contact us RIGHT NOW!