How to Monitor PHP Errors in WordPress Site

Would you like to have a well-performing, secure and healthy WordPress website on your hand? Then it is essential that you constantly monitor the php errors in wordpress.  If the PHP errors are not properly monitored, it can lead to error accumulation, and this will slow down your website performance. Aside from that, error accumulation will lead to bandwidth wastage.  Overall, your WordPress website will be exposed to malicious attacks, which will not bore well for the site and its contents.

No one can predict when PHP error can occur; its occurrence is spontaneous and highly unpredictable. The slightest action, like a change in the WordPress hosting server configuration, can also render your website vulnerable to PHP error. Simple actions like changing your WordPress files or changing your database setup can also culminate to PHP error.

php errors in WordPress

When PHP errors occur initially, you may never notice that things are going bad since the website will appear normal on the surface.  Unknown to you, the poor WordPress website is suffering underneath from these undetected PHP errors, exposing it to malicious attacks. You should get the PHP error detected and repaired on time before the damage becomes extensive.

Every responsible WordPress administrator should be engaged in PHP error monitoring. How can you successfully monitor PHP errors and prevent your WordPress from crashing over time? You will learn about simple processes you can follow in this write-up for successful monitoring of your website for PHP errors.

Method 1: Error-logging using the WordPress configuration file


Many have labeled this method as the easiest of all available methods to monitor PHP errors on your website.  All you need to do in this situation is to simply add some lines of codes to the wp-config.php file on your WordPress.  You can also use the wp-config.php file for specifying different PHP initiation settings toward modifying the functionality of your PHP installation.  How does this method monitor php errors in WordPress? Check below for steps to follow.

Step 1: Create a log file

First of all, create an empty file labeled “php-errors.log.” The site serves as the PHP error log.  You need to give your server write access to this new file you just created. Just set the permission before continuing.  You can place the file in any directory, but it is better to place it on top of the web-accessible root directory on the site. Take good note of the absolute directory path of the new file created before moving to the next step.

Step 2: Add the magic code

The next step starts with opening the wp-config.php file in your website and copy the code below into it. Make sure the code is placed above the line saying “That’s all, stop Editing! Happy blogging.” This is the code:

After copying the above code into the prescribed space, you can now edit the third line using the absolute directory path to the php-errors.log file that you created in the first step.  Next, get it uploaded to your server and that is it. From then on, the PHP errors detected will be logged to the php-errors.log file, and this will enable you to monitor and also resolve all the errors quickly easily.

You can make all the WordPress debug errors to be written to your php-errors.log file by using this code below

Method 2: Error logging through the php.ini file

You can monitor PHP error using this method if you can access the php.ini file on your site or if you can implement “per-directory” initiation files. You can use this method to easily initiate files on websites powered by WordPress and those powered by other websites.   There is a strong similarity between this method and the one discussed earlier.

Step 1: Create log file

First of all, create an empty file like you did in the first method. Name the empty file as “php-errors.log” this new file will be your PHP error log file. Also, set permission for the file so as to allow your website to write in the new file for monitoring php errors in wordpress.  It is better to place the file in the web-accessible root directory, and this will improve on security. Take a mental note of the absolute directory path of this file before continuing top the next step.

php errors in WordPress

Step 2: Add the magic code

Just like you did in the first example, you also need to add a magic code to the empty file you earlier created.  The first thing to do in this step is to open the php.ini file of the website and copy the code below in the file:

;;; log php errors

The code will help log all errors in this file.  Get the absolute directory path for the log file edited, and that is all.

Method 3: Error logging through the HTAccess file

This method also works perfectly for monitoring php errors in WordPress. Aside from WordPress, this method can also log PHP error in virtually any website.  Some similarities also exist between this method and the other ones mentioned earlier.

Step 1: Create a log file

Just like we did in the first two methods earlier described, we are also going to create a log file and title it php-errors.log. You also need to create write access for this file so that your server can write into it. It is also better to place this file above the web-accessible root directory of your website for enhanced security. Memorize the absolute directory path of the file created before moving to the next step.

Step 2: Add the magic code

The next thing to do is to open the .htacecss file in your website’s root. Afterward, add the code below:

The code is perfectly configured to monitor PHP errors. You are, however, required to edit the absolute directory path for the log file.

php errors in WordPress

Leave a Reply