Write access to /wp-content/debug.log in Wordpress

Problems with the Windows version of XAMPP, questions, comments, and anything related.

Write access to /wp-content/debug.log in Wordpress

Postby rjvt » 10. August 2022 10:10

I am trying to debug outgoing emails in Wordpress, but can't get write access to /wp-content/debug.log

I tried adding
Code: Select all
define( 'WP_DEBUG_LOG', '/tmp/wp-errors.log' );
as seen below and the output was logged to C:\xampp\apache\logs\error.log as expected.

But I prefer to use /wp-content/debug.log so I hope someone can help with setting up the permissions correctly.

Thanks!

Code: Select all
// An example wp_mail() override that you can place in your site's wp-config.php
// https://www.itthinx.com/2021/09/06/wordpress-mail-debugging/

define( 'WP_DEBUG', true );
define( 'WP_DEBUG_LOG', true );
define( 'WP_DEBUG_DISPLAY', true );
define( 'WP_DEBUG_LOG', '/tmp/wp-errors.log' );

function wp_mail( $to, $subject, $message, $headers = '', $attachments = array() ) {
  $output = sprintf(
    "\n\n" .
    "---------- Caught email ---------- \n\n" .
    "To: %s\n\n" .
    "Subject: %s\n\n" .
    "Message: %s\n\n" .
    "Headers: %s\n\n" .
    "Attachments: %s\n\n" .
    "---------------------------------- \n\n" .
    "\n\n",
    $to,
    $subject,
    $message,
    json_encode( $headers ),
    json_encode( $attachments )
  );
  error_log( $output );
  return true;
}

/* That's all, stop editing! Happy publishing. */
rjvt
 
Posts: 2
Joined: 10. August 2022 10:02
XAMPP version: 3.3.0
Operating System: Windows 10

Re: Write access to /wp-content/debug.log in Wordpress

Postby rjvt » 11. August 2022 11:04

I found the solution:

Give write access to the wp-content\debug.log file:

  • Right-click on C:\xampp\htdocs\vt\wp-content\debug.log
  • Remove check mark under Read-only at the bottom
  • Select Ok
  • Restart Apache in XAMPP, click Stop og Start

Block sending out email, log them
To block outgoing email and save to log file instead, insert the text below in wp-config.php above /* That's all, stop editing! Happy publishing. */:

Code: Select all
// An example wp_mail() override that you can place in your site's wp-config.php
// https://www.itthinx.com/2021/09/06/wordpress-mail-debugging/

define( 'WP_DEBUG', true );
define( 'WP_DEBUG_LOG', true );
define( 'WP_DEBUG_DISPLAY', false );

function wp_mail( $to, $subject, $message, $headers = '', $attachments = array() ) {
  $output = sprintf(
    "\n\n" .
    "---------- Caught email ---------- \n\n" .
    "To: %s\n\n" .
    "Subject: %s\n\n" .
    "Message: %s\n\n" .
    "Headers: %s\n\n" .
    "Attachments: %s\n\n" .
    "---------------------------------- \n\n" .
    "\n\n",
    $to,
    $subject,
    $message,
    json_encode( $headers ),
    json_encode( $attachments )
  );
  error_log( $output );
  return true;
}

/* That's all, stop editing! Happy publishing. */

See the email in the log file
Open wp-content\debug.log and finde the text, search for --Caught email.

For more, see:

WordPress Mail Debugging - https://www.itthinx.com/2021/09/06/wordpress-mail-debugging/
Debugging in WordPress - https://wordpress.org/support/article/debugging-in-wordpress/
rjvt
 
Posts: 2
Joined: 10. August 2022 10:02
XAMPP version: 3.3.0
Operating System: Windows 10

Re: Write access to /wp-content/debug.log in Wordpress

Postby mulaqucisi » 20. May 2023 04:09

I was facing same issue for my Website then i found the solution you can aslo check:

To enable write access to the /wp-content/debug.log file, you need to do the following:

Log in to your web server using an FTP client.
Navigate to the /wp-content directory.
Right-click on the debug.log file and select "Properties".
In the "Permissions" tab, set the "Owner" and "Group" permissions to "rw".
Set the "Other" permissions to "r".
Click "OK" to save your changes.
Once you have made these changes, WordPress should be able to write to the debug.log file.

If you are still having trouble, you can try the following:

Make sure that you are using a valid FTP client.
Make sure that you are logged in to the correct web server.
Make sure that you have the correct permissions set for the debug.log file.
Try restarting your web server.
If you are still having trouble, you can contact your web hosting provider for assistance.

Here are some additional tips for debugging outgoing emails in WordPress:

Enable WordPress debug mode. This will cause WordPress to log all errors and warnings to the debug.log file.
Use the wp_mail() debugging function. This function will log all email messages that are sent through WordPress to the debug.log file.
Use a third-party email debugging tool. There are a number of third-party email debugging tools available that can help you troubleshoot email problems in WordPress.
mulaqucisi
 
Posts: 1
Joined: 20. May 2023 04:04
XAMPP version: 8
Operating System: Window


Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 165 guests

cron