Make runtime errors visible in WordPress
When we program, it is imperative to be able to see the errors that are generated during the runtime in order to correct them.
On some occasions, these errors are evident by throwing blank screenshots, but on others, they are much more subtle and only manifest themselves in very specific circumstances. Of course, when we are carrying out a complex development, it is important to have at least one clue of what may be failing between the thousands and thousands of lines of code, and for this, there are the error logs.
WordPress, like almost all developments of this type, hides those errors for security. Since showing them, not only would they look ugly for our visitors, but it could give clues to malicious programmers where there is a vulnerability.
In this article, you will get to know, how to enable the display of errors, record them and display them internally.
How to enable the display of errors, record, and display
There are two ways for this:
- By hand: Configuring wp-config.php
- With a plugin
#1. By hand: Configuring wp-config.php
First, we create a file called php-errors.log, and we place it in the index of our website via FTP. After that, just assign read and write permission for you.
At the root of your WordPress installation, there is a file called wp-config.php.
Make a backup copy and edit it by adding the following code at the end of the file. Following the line that says:
Code:
// mostrar errores de php @ini_set('log_errors','On'); // habilita o deshabilita el registro de errores (utiliza 'On' u 'Off') @ini_set('display_errors','On'); // Los errores se muestran en la parte pública (utiliza 'On' u 'Off') @ini_set('error_log','/var/www/vhosts/tudominio.com/httpdocs/php-errors.log'); // ruta del archivo que hemos creado previamente
Where you should replace yourdomain.com by your page.
It is important to say that the absolute path of the file may vary depending on the structure of the server. The one reflected above is the URL in Plesk and Odin, but if you use cPanel, it would be something like:
@ini_set('error_log','/home/tudominio.com/tmp/php-errors.log'); // ruta del archivo que hemos creado previamente
In any case, if you create an info.php, at the end of it, on the line _SERVER («DOCUMENT_ROOT»), The path of your server appears.
Finally, on his own wp-config.php, We end up in the line that says:
define('WP_DEBUG', false);
And we replaced it with:
define ('WP_DEBUG', true); // Habilitar el modo de depuración define ('WP_DEBUG_LOG', true);
Finally, something like:
Just save it and upload it to FTP. Now, we are ready to register errors.
These will be shown both in the public part (when we access a page that generates an error), as in the file we have created.
To view the error log, simply open it with a text editor. type notepad.
#2.With a plugin
The plugin Error Log Monitor, is a free addon that allows you to show errors on the WordPress Desktop, and even send you reports of them, by email, from time to time.
It is very useful both to solve a specific problem, and to monitor own developments and locate errors of execution.
That’s it.