DEV Community

Mahbub Rabbani
Mahbub Rabbani

Posted on • Updated on

WordPress Error Log Not Showing with Laravel Herd

As a developer working with both WordPress and Laravel, I prefer to use the same development environment for efficiency. For local development, I always use Laravel Herd. However, I encountered an issue where the WordPress error log was not showing up in my development setup.

After extensive debugging, I discovered that Laravel Herd logs errors to /Users/{username}/Library/Application Support/Herd/Log/php-fpm.log.

I attempted to set the path explicitly using ini_set('error_log', WP_CONTENT_DIR . '/debug.log'), but ini_get('error_log') consistently returned the Laravel Herd default path: /Users/{username}/Library/Application Support/Herd/Log/php-fpm.log. Interestingly, the error logging worked perfectly from the WP CLI shell but not through the browser.

To resolve this issue, I decided to create a symlink in wp-config.php as follows:

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

// Target file or directory
$target = ini_get('error_log');

// Symlink path
$link =  __DIR__ .'/wp-content/debug.log';

if ( ! is_link( $link ) && file_exists( $link ) ) {
    unlink( $link );
}

// Check if the symlink already exists
if (! ( file_exists( $link ) || is_link( $link ) ) ) {
    symlink($target, $link);
}
Enter fullscreen mode Exit fullscreen mode

Alternative solution https://stackoverflow.com/a/77102145.

Top comments (0)