4 Ways to Get WordPress PHP Error Logs

by

When working with WordPress, encountering errors is a common part of the development and maintenance process. However, the real challenge lies in accurately diagnosing and resolving these issues. One of the most effective tools at your disposal is the PHP error log. By using PHP error logs, you can gain invaluable insights into the underlying problems within your WordPress site, allowing for more efficient troubleshooting.

In this article, we will dive into the two ways to create and utilize PHP error logs in WordPress: using a plugin, and manually configuring system files. Whether you’re a seasoned developer or a WordPress beginner, understanding how to access and read these logs is crucial. We’ll cover multiple methods to ensure that you can configure error logging to fit your specific needsā€”with tips for both modifying configuration files and using plugins tailored for this purpose.

TL;DR: WordPress PHP error logs can be essential for troubleshooting issues on your website. You can obtain them either by using a plugin like Error Log Monitor or by manually editing system files like wp-config.php, php.ini, or .htaccess.

Does your web host provide WordPress PHP error logs?

While it’s common for web hosts to offer access to web server logs, PHP error logs might not be as readily available. However, if you’re with Cloudways or WP Engine, you’re in luck, as both provide PHP error logs on their dashboards.

Cloudways users can simply navigate to Application Management on their dashboard and click on Monitoring. In the sub-menu, click on Logs and select the Error Logs option. Use the search button and enter ‘php’ to look for PHP error logs.

Cloudways Error Logs

If you are a WP Engine user, click on Site details on your dashboard and go to the Logs section. You can then search for ā€˜phpā€™ in the logs to filter out your required error logs.

WP Engine PHP Error Logs

If you use any other web host, check their documentation or contact support to know where you can find your PHP error logs. In case your web host hasnā€™t enabled or made accessible the PHP error logs, you will need to either use a plugin or manually make changes to system files. Always be cautious when editing system files and ensure you take backups before making changes.

1. Get WordPress PHP error logs using a plugin

While the WordPress plugin repository has several options that can help obtain logs, not all of them provide PHP error logs specifically. This is where Error Log Monitor by Janis Elsts comes in. It is a very simple plugin that does exactly one thing: obtain PHP error logs, and does it extremely well.

To use it, go to the Plugins option of your WordPress dashboard and click on Add New Plugin. Search for Error Log Monitor, click on Install, and then on Activate. You are done!

Error Log Monitor by Janis Elsts

This will add a new view on your WordPress siteā€™s admin dashboard where you can see your PHP error log. It also gives you the option to mark errors as resolved or ignore them, as well as to clear the error log. It also provides the location of the error log file which can be helpful for more technical users. The only issue with this plugin is that you cannot download the logs as displayed on your dashboard.

PHP error logs from Error Log Monitor by Janis Elsts

The plugin method suffices for most users as it is easy and creates the error logs in the default location of the wp-content folder in the root directory. However, if you are a power user who wants to create the error logs in a separate directory/file, the plugin does NOT offer you the option to do so. In that case, you may want to use one of the following manual methods of creating WordPress error logs.

2. Get WordPress PHP error logs by manually editing the wp-config.php file

Before you begin to edit any of the WordPress system files, creating an up-to-date backup of your WordPress site is essential. This crucial step allows you to restore your site exactly as it was if anything goes wrong during the editing process.

Use a WordPress backup plugin like BlogVault to make the process straightforward and secure. Its real-time backup feature ensures you always have the most up-to-date backup of your site, saving you time and effort when restoring your site.

Once the backup is ready, letā€™s look at how to manually edit the wp-config.php file. We are using the Filezilla FTP client for this, and here are the steps:

  1. Log in to your site using Filezilla: Open Filezilla, enter your login credentials like public IP address, username, password, and port number (if available), and click on Quickconnect. These credentials can be found on your web hostā€™s dashboard or obtained from your hosting provider.

1. Create php_errors.log file: This file will be used to store PHP error logs. Navigate to your preferred location on the right-side pane, right-click on any white space, and select Create new file. Enter the name as php_errors.log and click on OK.

2. Edit the wp-config.php file: Locate the wp-config.php file in your root directory using the right-side pane. Right-click on it and select View/Edit. This opens up the file in your default text editor.

filezilla wp-config.php view/edit

Add the following lines of code to it:

// log PHP errors
@ini_set('log_errors','On');
@ini_set('display_errors','Off');
@ini_set('error_log','path/php-errors.log');

These lines enable the PHP error logging feature, prevent it from displaying the error messages on the site for logged-in users, and log them to the php-errors.log file. Remember to replace the path value with the correct directory path to your log file.

3. Save the wp-config.php file: Finally, save the wp-config.php file by entering Ctrl+S for Windows PCs or Command+S for MacOS. Close the text editor window to bring a pop-up that asks if you want to upload the file back to your site. Click on Yes and you are done!

filezilla file edit upload to server

3. Get WordPress PHP error logs by manually editing the php.ini file

  1. Log in to your site using Filezilla: Connect to your site through FTP using your login credentials.
  2. Locate or create the php.ini file: Find the php.ini file in the wp-admin directory or use the steps mentioned previously to create it in that directory if it does not exist.
  3. Create php_errors.log file: Similar to the previous section, create the php_errors.log file in your preferred directory.
  4. Edit the php.ini file: Open the php.ini file in your default text editor in Edit mode as shown in the previous section, and add the following lines of code to it:
;;; log php errors
display_startup_errors = false
display_errors = false
html_errors = false
log_errors = true
track_errors = true
error_log = path/php-errors.log
error_reporting = E_ALL | E_STRICT
log_errors_max_len = 0

Remember to change the path value to the correct directory path to your log file.

  1. Save the php.ini file: Enter Ctrl+S for Windows PCs or Command+S for MacOS to save the changes. Reupload the modified file back to your site by closing the text editor window and clicking on Yes in the ensuing pop-up window.

4. Get WordPress PHP error logs by editing the .htaccess file

  1. Log in to your site using Filezilla: Connect to your site through FTP using your login credentials.
  2. Create php_errors.log file: Similar to the previous sections, create the php_errors.log file in your preferred directory.
  3. Edit the .htaccess file: Locate the .htaccess file in the public_html directory and open it in your default text editor in Edit mode as shown in the previous sections. Next, add the following lines of code to it:
# 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 /path/php-errors.log

Remember to change the path value to the correct directory path to your log file.

  1. Save the .htaccess file: Enter Ctrl+S for Windows PCs or Command+S for MacOS to save the changes. Reupload the modified file back to your site by closing the text editor window and clicking on Yes in the ensuing pop-up window.

FTP alternatives to edit system files

In all the aforementioned methods to edit system files, we have used an FTP client like Filezilla. In case you were wondering, here are two other ways to do the same without using an FTP client:

Modify system files using the cPanel File Manager

  1. Log in to your web hostā€™s cPanel and click on File Manager to open it.
cPanel File Manager (New Look Dec 2023)
  1. Navigate and locate your file by using the left-side pane. Right-click on it and select Edit. Click on Edit again in the pop-up box. Add your modifications and click on Save Changes.
cPanel File Manager public_html wp-config.php file edit
  1. To create a file, navigate to your preferred location using the left-side pane. Click on the directory where you want to create your file and then click on the +File icon on top. In the ensuing pop-up box, enter your preferred file name, check if your destination folder is correct, and click on Create new file.
cPanel File Manager create new file

Modify system files using Secure Shell (SSH)

  1. Log in to your site through SSH with your credentials, using Command Prompt for Windows or Terminal for Macs.
  2. Navigate to your required directory with the command cd directory_name and list all files present in the particular directory with the command ls -a.
  3. To edit a file, enter the command vi file_name, hit i key, and make your changes. Once done, hit Esc and enter the command :wq to save your changes.
  4. To create a file, navigate to your required directory and enter the command touch file_name, where file_name is the file you want to create.

Is debug.log a good place to find PHP errors?

Enabling WordPress debugging requires editing the wp-config.php file and setting it to log errors or warnings across your entire WordPress site. This data is recorded in the debug.log file in the wp-content directory.

Since it records messages from all over your WordPress site, it also contains PHP errors within itself. So, it can also be used as a PHP error log. However, it contains errors and warnings of all kinds, which could make it difficult to sort the PHP errors out. This is why the steps mentioned in this article create a separate log only for PHP errors, making your job easier.

WordPress debug log

How to find and check your WordPress PHP error logs?

If your web host provides a PHP error logging feature, you can simply access it from your web hostā€™s dashboard.

In case you manually set up PHP error logging for your WordPress site, you can find and check your logs by using FTP, cPanelā€™s File Manager, or SSH.

Checking WordPress PHP error logs using FTP

  1. Connect to your site using FTP: Use the steps mentioned earlier to connect to your site using an FTP client like Filezilla.
  2. Locate PHP error logs: If you have manually set up PHP error logging on your WordPress site, the error logs will be located in your specified directory.
  3. Download your PHP error log file: Once you have located your error log files, download them by right-clicking on them and selecting Download. This will download the file to the location selected on the left pane of your Filezilla window. If you wish to download the file to any other location, navigate to that location using the left pane.
  4. Open your PHP error log file using a text editor: Now that you have downloaded the PHP error log, open it using Notepad or any other text editor you prefer. You can scroll through the data and identify the exact message informing you of the error/issues.

Checking WordPress PHP error logs using the cPanel File Manager

  1. Log in to your siteā€™s cPanel: Go to your WordPress siteā€™s cPanel and log in using your credentials.
  2. Locate PHP error logs: Click on File Manager and locate your PHP error logs in the folder where you created them.
  3. Download your PHP error log file: Right-click on your PHP error log file and click on Download to get it on your system.
  4. Open your PHP error log file using a text editor: Open the downloaded PHP error log using Notepad or any other text editor you prefer. You can scroll through the data and identify the exact message informing you of the error/issues.

Checking WordPress PHP error logs using SSH

1. Connect to your site using SSH: Use the steps mentioned earlier to connect to your site using Command Prompt for PCs or Terminal for Macs.

2. Locate PHP error logs: As mentioned in the steps to check PHP error logs using FTP, the files will be located in the folder of your choice. Navigate to the required folder by entering the following command:

cd your_folder/logs_folder

where your_folder/logs_folder can be replaced by the correct location.

Next, enter the following command to list all the files in that folder:

ls -a

3. View your PHP error logs: To view your PHP error logs, simply open your required file in the Vmacs editor by entering the following command:

vi file_name

where file_name can be replaced by the error log name.

You can then scroll through the logs using the arrow keys. Enter :q to quit the editor.

If you are looking for a particular message or timeframe, you can use the grep command instead of opening the file in an editor. Type the following to find the particular text you are searching for in the error log file:

grep text file_name

where text is what you are searching for and file_name is where you are searching for it.

How to fix issues discovered in WordPress PHP error logs?

The PHP error log file provides valuable information about four types of errors on your WordPress website: Warning, Notice, Parse, and Fatal Error. However, they can appear technical to most users, which is why understanding these messages is critical to resolving any issues.

Each entry in the PHP error log file typically includes the date, time, error type, and finally the error message. This error message is often enough to understand the problem. However, to fix the problem, you will have to go through guides and how-tos on it.

PHP errors

To simplify the process of understanding the contents of the PHP error log file, here are the steps:

  • Identify the error or warning in the PHP error log file.
  • If the problem is caused by a plugin or theme, try reinstalling it or updating it. If it still does not work, try reaching out to the plugin developer or find a replacement.
  • For more complex issues, you might need to consult the official PHP documentation.
  • Sometimes updates are the reason behind PHP errors, so roll back recent updates and see if this fixes your issue.

When should you obtain WordPress PHP error logs?

The PHP error logs in WordPress are a repository of information that can alert you to a variety of issues on your website. Understanding when to access these logs is key to maintaining a healthy and smoothly operating site. Here are common scenarios when you should consider checking the PHP error logs:

  • If your WordPress site has crashed, is unresponsive, or is not loading
  • If you get HTTP warnings like 401, 404, 500, 504, etc. with a White Screen of Death when loading your website or any specific pages on it
  • If you see any of your themes or plugins not working properly
  • After an update or change to WordPress core, themes, and plugins to check for potential errors or warnings

Troubleshooting

If you are unable to obtain logs even after following the steps mentioned above, you can try the following steps:

  • Check whether the PHP error logging plugin is compatible with your WordPress version, or if it has an update available. If it requires an update, update safely.
  • Check if the code you entered into the files is correct. A minor mistake could be enough to prevent your site from logging data, or worse, crash it.
  • Check if a plugin on your site is preventing the files from being edited. Usually, security plugins do this as a measure of protection against unwanted modifications to system files.

In the third case, you might need to disable the security plugin during the error logging process. However, it is not advisable as disabling a security plugin could render your WordPress site vulnerable to threats. This is why we recommend using MalCare, a robust security plugin that not only protects your site but also has comprehensive logging built-in.

Final thoughts

Being vigilant about your PHP error logs is a best practice in WordPress management. Regularly monitoring these logs helps catch issues early, providing a solid foundation for troubleshooting and reinforcing your WordPress site’s stability, performance, and security.

If monitoring your WordPress site at all times is too much of a task, use a security plugin like MalCare. Its robust firewall capabilities, strong malware detection and removal feature, as well as comprehensive logs can be just the right additions to your siteā€™s security regimen.

FAQs

Where can I find the PHP error log file in WordPress?

PHP error logs are typically located in your website’s root directory, within the `wp-content` folder, or your web server’s directory structure (often named `error_log`). The exact location can vary depending on your hosting provider and server configuration.

Can I access PHP error logs from the WordPress admin dashboard?

WordPress by default does not display PHP error logs in the admin dashboard. However, there are plugins available, like Error Log Monitor, that can provide this functionality, allowing you to view the logs without accessing the server directly.

What kind of information can I find in a PHP error log?

PHP error logs contain details about the error type (e.g., warning, parse error, fatal error), the error message, the file path where the error occurred, and the line number inside the file.

How do I read and interpret the PHP error logs?

To read PHP error logs, access the log file via FTP or a file manager provided by your hosting service. Look for entries that correlate with the time the issue occurred and interpret the error message, the script involved, and check the code around the specified line number.

What should I do if I can’t find the PHP error logs?

If you can’t find the PHP error logs, check your hosting provider’s documentation or contact their support for assistance. Some hosts may store logs in a different location or provide a dedicated tool in their control panel to access error logs.

What do I do if my PHP error logs are empty despite having issues on the website?

If your PHP error logs are empty, make sure PHP logging is properly enabled and that there aren’t server-level issues preventing the logs from being written. Additionally, some issues may be due to JavaScript or other non-PHP-related errors, which won’t be logged in the PHP error logs.

Category:

You may also like


MalCare Free vs Premium: Differences Explained
MalCare Free vs Premium: Differences Explained

MalCare is a new face in WordPress plugins for security, but is considered a strong contender alongside the biggest names like Wordfence and Sucuri. But, does it make sense to…

How can we help you?

If you’re worried that your website has been hacked, MalCare can help you quickly fix the issue and secure your site to prevent future hacks.

My site is hacked – Help me clean it

Clean your site with MalCare’s AntiVirus solution within minutes. It will remove all malware from your complete site. Guaranteed.

Secure my WordPress Site from hackers

MalCare’s 7-Layer Security Offers Complete Protection for Your Website. 300,000+ Websites Trust MalCare for Total Defence from Attacks.