Skip to content

Instantly share code, notes, and snippets.

@geraldvillorente
Last active March 7, 2019 16:13
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save geraldvillorente/429ec7e925e73b21773553722edeadb8 to your computer and use it in GitHub Desktop.
Save geraldvillorente/429ec7e925e73b21773553722edeadb8 to your computer and use it in GitHub Desktop.
Managing Wordpress debug.log on Pantheon

Wordpress has its own debugging system that Pantheon customers can leverage. Below is the setup that should be able to work regardless of environment connection mode.

Place this code on wp-config.php:

if (defined('PANTHEON_ENVIRONMENT')) {
    // Wordpress debug settings in Development and Test environments.
    if (!in_array(PANTHEON_ENVIRONMENT, array('live'))) {
      // Debugging enabled.
      if (!defined( 'WP_DEBUG' )) {
        define( 'WP_DEBUG', true );
      }
      // Stored in wp-content/debug.log
      define( 'WP_DEBUG_LOG', true ); 
      define( 'WP_DEBUG_DISPLAY', false );
    }
    // Wordpress debug settings in live environment.
    else {
      // Debugging disabled.
      ini_set('log_errors','On');
      ini_set('display_errors','Off');
      ini_set('error_reporting', E_ALL );
      define('WP_DEBUG', false);
      define('WP_DEBUG_LOG', true);
      define('WP_DEBUG_DISPLAY', false);
    }
}

Take note that the default debug.log location is code/wp-content/debug.php which is not writable when the server is in Git mode. In order to make make the WP_DEBUG work even on Git mode you need to create a plugin and place it in code/wp-content/mu-plugins.

  • Create a file called custom-debug-log-path.php or whatever name you like in code/wp-content/mu-plugins.
  • Place the below code in the file you created above.
<?php
/**
 * Plugin Name: Custom Debug Log Path
 */

if (defined('PANTHEON_ENVIRONMENT')) {
    //Wordpress debug settings in development environments.
    if (!in_array(PANTHEON_ENVIRONMENT, array('live'))) {
        define( 'WP_LOGS_DIR', sprintf( '/srv/bindings/%s/logs', PANTHEON_BINDING ) );
        // Override the default debug.log path as it is not going to work this in Git mode.
        if ( defined( 'PANTHEON_BINDING' ) ) {
            // Set the logs path. You can set the path to /srv/bindings/%s/code/wp-content/uploads which is also writable
            // all the time regardless of the connection mode. However, this is not a recommend way for security reason.
            define( 'WP_LOGS_DIR', sprintf( '/srv/bindings/%s/logs', PANTHEON_BINDING ) );
            ini_set( 'error_log', WP_LOGS_DIR . '/debug.log' );
        }
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment