Eduardo G's picture

Hello,. im using latest Turnkey Wordpress 16.0.

I want to have a log file with information, to debug possible problems and monitoring VM.

As wordpress documentation i write in wp-config:

// Enable WP_DEBUG mode
define( 'WP_DEBUG', true );

// Enable Debug logging to the /wp-content/debug.log file
define( 'WP_DEBUG_LOG', true );
//define( 'WP_DEBUG_LOG', 'wp-errors.log' );

// Disable display of errors and warnings
define( 'WP_DEBUG_DISPLAY', false );
@ini_set( 'display_errors', 0 );

// Use dev versions of core JS and CSS files (only needed if you are modifying these core files)
define( 'SCRIPT_DEBUG', true );

 

This should create and log to default file debug.log.

But i had to create manually the file, and always is empty. So no logging.

I have also changed permissions of wordpress folder to www-data:www-data.

Any help would be apreciated.

Forum: 
Jeremy Davis's picture

DId you restart the Apache webserver? As far as I'm aware, restarting the webserver is required to apply the updated setting. You can do that like this:

systemctl restart apache2

By default, the permissions should be as required for this to "just work". Although if you have manually made changes to files/directories within the WordPress root (/var/www/wordpress) such as manually creating the file/directory, please ensure that it is owned by the 'www-data' user (the webserver user). It sounds like you may have already done that, but just in case, to ensure that all the WordPress files are owned by the webserver, you can run this:

chown -R www-data:www-data /var/www/wordpress

If you have already followed those steps, and it still doesn't work as expected, please let me know and I'll see if I can get it to work as it should on a test server.

It may also be worth checking the Apache logs (/var/log/apache2) as they may contain some hint to what the issue may be?

Alternatively, if you have managed to fix it yourself (or do), please post back with whatever was required. That way the info will be available for others. Also, if there is a tweak that we can pre-configure to improve the appliance out of the box, then we'll do so.

Jeremy Davis's picture

FWIW it appears that even when it's configured correctly, despite the "debug" name, it won't actually log anything unless there is an error (although perhaps that's configurable?). I launched a test instance and configured my wp-config.php as per your notes:

// WordPress debugging mode (for developers).
define('WP_DEBUG', true);

// Enable Debug logging to the /wp-content/debug.log file
define( 'WP_DEBUG_LOG', true );
//define( 'WP_DEBUG_LOG', 'wp-errors.log' );

// Disable display of errors and warnings
define( 'WP_DEBUG_DISPLAY', false );
@ini_set( 'display_errors', 0 );

// Use dev versions of core JS and CSS files (only needed if you are modifying these core files)
define( 'SCRIPT_DEBUG', true );

And as you noted, there is no log file being created. However, when I added a line to the default (twentytwenty) theme, like this:

echo "error_log('Debug log loading');" >> /var/www/wordpress/wp-content/themes/twentytwenty/functions.php

Then I restarted Apache:

systemctl restart apache2

And reloaded the home page in my web browser. Then guess what? The debug.log file gets created! And it contains the message inserted into the theme! :)

root@jed-test-wordpress ~# find /var/www/wordpress/ -type f -name "*log"
/var/www/wordpress/wp-content/debug.log
root@jed-test-wordpress ~# cat /var/www/wordpress/wp-content/debug.log
[27-Jan-2021 08:00:01 UTC] Debug log loading
gbyczyk's picture

It also helped me. Thank you

Eduardo G's picture

Sorry for the delay,  but i was busy these days... As you can read : https://wordpress.org/support/article/debugging-in-wordpress/

First of all i had to create manually the file debug.log ( should be created by wordpress server)

It should ", will log all errors, notices, and warnings to a file called debug.log in the wp-content directory. It will also hide the errors so they do not interrupt page generation.". So seems its a bug or error.

I restarted the VM, and the permissions were as you said (www-data:www-data) in all /var/www/wordpress folder and inside ( -R option)

Thanks again for your help, and sorry for confuse forum post with github.

 

 

Jeremy Davis's picture

Ok, so I've had a little more of a look and as you note, applying the above mentioned settings should "cause all PHP errors, notices and warnings to be displayed."

That is clearly not what is happening (only errors being logged as I noted). So either it is a bug within WordPress, a poorly worded piece of documentation or there is some specific setting elsewhere that is required (which should be noted IMO)?! According to my reading, the WordPress "Debug" mode should override default php.ini settings (and should be able to), but perhaps for some reason it doesn't? According to my reading, these settings should also be set automatically by enabling WP Debug, but perhaps try updating the (apache2) php.ini to these values might help?:

  • display_errors = on
  • display_startup_errors = on
  • error_reporting = E_ALL

You could add these right at the bottom

Note that Apache needs to be restarted to apply php.ini or other config changes.

FWIW when trying to track down these sort of issues, the best way to go is split it up into the smallest possible chunks. I.e. in this case, it's probably worth enabling the error reporting first (so errors are displayed in the web browser). Once you can confirm that that works as desired, then enabling the logging to file to diagnose that component. That way you are only diagnosing one issue at a time. E.g. in your case, you would have realised that there was a problem with the amount of issue reporting, rather than wasting time on the possibility it was a file permissions issue, or some other filesystem problem.

Add new comment