Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

If you are using Kalabox, you should have some basic conditionals that setup your settings.php to operate on Pantheon and your local Kalabox:

Code Block
languagephp
themeRDark
linenumberstrue
/**
 * Terminatur
 *
 * These local settings were generated by terminatur.
 * You may see them if you use Kalastack, Kalabox, Proviso or other local dev
 * tools.
 *
 */
if (isset($_SERVER['KALABOX']) &&  $_SERVER['KALABOX'] === 'on') {
  // DB Array and some common conf.
  $databases['default']['default'] = array(
    'driver' => 'mysql',
    'database' => 'mysite_kala',
    'username' => 'root',
    'password' => 'password',
    'host' => 'localhost',
    'port' => '3306',
    'prefix' => '',
  );
  
  // Error reporting
Set some common desirable local vars.
  $conf['file_temporary_path'] = '/tmp'; error_reporting(-1);  // Have PHP complain about absolutely everything.
  $conf['fileerror_public_pathlevel'] = 'sites/default/files';
  $conf['file_private_path'] = 'sites/default/files/private';
  $conf['reroute_email_enable'] = 1;

  $conf['cache'] = 0;
  $conf['css_gzip_compression'] = FALSE;2;  // Show all messages on your screen
  ini_set('display_errors', TRUE);  // These lines give you content on WSOD pages.
  ini_set('display_startup_errors', TRUE);

  // Set some common desirable local vars.
  $conf['jsfile_gziptemporary_compressionpath'] = FALSE'/tmp';
  $conf['preprocessfile_public_csspath'] = 0'sites/default/files';
  $conf['preprocessfile_private_jspath'] = 0'sites/default/files/private';
  $conf['sitereroute_email_nameenable'] = 'mysite Local';1;

  $conf['cron_lastcache'] = '9999999999';
}

 

Non-Kalabox

If you aren't on Kalabox, you should setup something similar. Make sure you don't overwrite any of the existing Kalabox settings or Pantheon configuration:

Code Block
languagephp
linenumberstrue
if (isset($_SERVER['KALABOX']) &&  $_SERVER['KALABOX'] === 'on') {
 // Kalabox stuff from above would be here.
} else {
 // Your custom local environment db configuration and the sane defaults
 // shown in the Kalabox config above should be here.
}

301 Redirect to Single Domain

On most sites that are going live, we'll want to make sure all requests are directed to a single domain for ideal SEO and user experience. We do this with a permanent 301 redirect.

...

0;
  $conf['css_gzip_compression'] = FALSE;
  $conf['js_gzip_compression'] = FALSE;
  $conf['preprocess_css'] = 0;
  $conf['preprocess_js'] = 0;
  $conf['site_name'] = 'mysite Local';
  $conf['cron_last'] = '9999999999';
}

 

Non-Kalabox

If you aren't on Kalabox, you should setup something similar. Make sure you don't overwrite any of the existing Kalabox settings or Pantheon configuration:

Code Block
languagephp
themeRDark
linenumberstrue
if (isset($_SERVER['PANTHEON_ENVIRONMENTKALABOX'])) {&&   if($_SERVER['KALABOX'PANTHEON_ENVIRONMENT'] === 'liveon') {

   // settingsKalabox forstuff launchingfrom Featuredabove Eventswould be here.
}  if($_SERVER['HTTP_HOST'] == 'live-mysite.gotpantheon.com' || $_SERVER['HTTP_HOST'] == 'www.mysite.com'){
      header('HTTP/1.0 301 Moved Permanently');
      header('Location: http://mysite.com'. $_SERVER['REQUEST_URI']);
      exit();
    }
  }
}

 

Full Settings.php Sample

Here is an example portion of a settings.php with environmental magic on Pantheon

There is an example 404 redirect config, and a redirect for a path part to a subdomain.

Also, a placeholder for 301 redirects.

(warning) note that there are 2 different ways to check the Pantheon environment, here – one for config, the other for web actions like redirects.

Code Block
themeRDark
languagephp
titlesetttings.php
<?php
 
// all other defaults go here
 

/*
* settings for all environements
*/
// Avoid Image resize threshold error
$conf['image_resize_filter_threshold'] = 1000;
// 7.21+ image hack for text-area images
// http://drupal.stackexchange.com/questions/63226/drupal-7-20-image-styles-return-a-url-with-access-denied
$conf['image_allow_insecure_derivatives'] = TRUE;

/**
 * Perform web-only operations on Pantheon like redirects
 * the $_SERVER array will not exist for the drush-cli
 * see http://helpdesk.getpantheon.com/customer/portal/articles/708588
 */
if (issetelse {
 // Your custom local environment db configuration and the sane defaults
 // shown in the Kalabox config above should be here.
}

301 Redirect to Single Domain

On most sites that are going live, we'll want to make sure all requests are directed to a single domain for ideal SEO and user experience. We do this with a permanent 301 redirect.

In this example, we're making sure that the default Pantheon domain AND www.mysite.com are redirected to the non-www domain:

Code Block
languagephp
themeRDark
linenumberstrue
if (isset($_SERVER['PANTHEON_ENVIRONMENT'])) {
  if($_SERVER['PANTHEON_ENVIRONMENT'] === 'live') {
    // settings for launching Featured Events
    if($_SERVER['HTTP_HOST'] == 'live-mysite.gotpantheon.com' || $_SERVER['HTTP_HOST'] == 'www.mysite.com'){
      header('HTTP/1.0 301 Moved Permanently');
      header('Location: http://mysite.com'. $_SERVER['REQUEST_URI']);
      exit();
    }
  }
}

 

Partial Redirects going to legacy site with a new site (Kettering did this)

Code Block
languagephp
themeRDark
linenumberstrue
// REDIRECTS
if (isset($_SERVER['PANTHEON_ENVIRONMENT'])) {
  // Easily Change status code and base url for testing here:
  $host = 'my.kettering.edu';
  $http_code = 'HTTP/1.0 303 See Other';
  $redirect = FALSE;

  // Add URLS to skip this AKA 1-1:
  $skip = array(
    '/admissions',
  );

  // Set this to a var so we don't mess with doing all this fun stuff below.
  $uri = strtolower($_SERVER['REQUEST_URI']);

  // Redirect to legacy site based on set patterns, etc.
  if (!in_array($uri, $skip)) {
    // Wildcard Redirects.
    $wildcard = array(
      'academics',
      'alumni-donors',
      'current-students',
      'downloads',
      'emergency',
      'faculty-staff',
      'faculty',
      'ferpa',
      'it',
      'news',
      'office-administration',
      'offices-administration',
      'research',
    );

    // One to One from www.kettering.edu to my.kettering.edu
    $onetoone = array(
      '/archives',
      '/asc',
      '/Atwood',
      '/brand',
      '/businessOffice',
      '/career-services',
      '/cetl',
      '/commencement',
      '/communityservice',
      '/currentstudents',
      '/deans-list',
      '/dining',
      '/emergency',
      '/employee-information',
      '/events',
      '/ferpa',
      '/financialaid',
      '/financialAid',
      '/first',
      '/flintwater',
      '/get-word-out',
      '/give',
      '/greeklife',
      '/hr',
      '/keepmekettering',
      '/library',
      '/marcomm',
      '/nbs',
      '/Oldschool',
      '/phonathon',
      '/regbell',
      '/registrar',
      '/sharing-memories-professor-bell',
      '/studentlife',
      '/trustee-rsvp',
      '/water',
      '/wellness-center',
    );

    // String Match Redirects.
    $string_checks = array(
      '/about/accreditation-and-assessment',
      '/sites/default/files/resource-file-download',
    );

    // Time to make the magic happen.
    $uri_check = explode('/', $_SERVER['REQUEST_URI']);

    // Check for Wildcard Redirect || 1 to 1 www to my first.
    if ((isset($uri_check[1]) && in_array($uri_check[1], $wildcard)) ||
        (in_array($uri, $onetoone))) {
      $redirect = TRUE;
    }
    // Redirect to specific legacy pages or paths.
    elseif (isset($uri_check[1])) {
      // Change the URI or HOST based of the base uri path.
      switch ($uri_check[1]) {
        case 'alumni':
          $redirect = TRUE;
          $uri = '/alumni-donors/get-involved';
          break;
        case 'directory':
          $redirect = TRUE;
          $uri = '/faculty-staff/directory';
          break;
        case 'giving':
          $redirect = TRUE;
          $uri = '/give';
          break;
        case 'aanouncements':
          $redirect = TRUE;
          $uri = '/announcements';
          break;
        case 'partnerships':
          $redirect = TRUE;
          $uri = '/alumni-donors';
          break;
        case '~':
          $redirect = TRUE;
          $host = 'paws.kettering.edu';
          break;
        case 'ug-admitted':
          $redirect = TRUE;
          $host = 'accepted.kettering.edu';
          break;
        case 'iamabulldog':
          $redirect = TRUE;
          $host = 'accepted.kettering.edu';
          break;
        case 'admissions':
          // This was the easiest way to handle all the admissions ones.
          $redirect = TRUE;
          unset($uri_check[1]);
          $uri = implode('/', $uri_check);
          $host = 'www.kettering.edu';
          break;
      }
      // Check for string paths.
      if (!$redirect) {
        foreach ($string_checks as $string_check) {
          if (strpos($uri, $string_check) !== FALSE) {
            $redirect = TRUE;
          }
        }
      }
    }
  }
  // If true above, lets have some fun redirects happen!
  if ($redirect) {
    header($http_code);
    header('Location: https://'. $host . $uri);
    exit();
  }
  else {
    // Regular redirects to current site.
    $old = array(
      'm.kettering.edu',
      'admissions.kettering.edu',
    );

    if ($_SERVER['PANTHEON_ENVIRONMENT'] === 'live' && $_SERVER['HTTPS'] === 'OFF') {
      if (!isset($_SERVER['HTTP_X_SSL']) ||
         (isset($_SERVER['HTTP_X_SSL']) && $_SERVER['HTTP_X_SSL'] != 'ON')) {
        header($header);
        header('Location: https://www.kettering.edu' . $_SERVER['REQUEST_URI']);
        exit();
      }
    }
    elseif ($_SERVER['PANTHEON_ENVIRONMENT'] === 'live' && in_array($_SERVER['HTTP_HOST'], $old)) {
      header($header);
      header('Location: https://www.kettering.edu'. $_SERVER['REQUEST_URI']);
      exit();
    }
    elseif ($_SERVER['HTTP_HOST'] == 'my.kettering.edu') {
      $newurl = 'https://www.kettering.edu/faculty-staff'. $_SERVER['REQUEST_URI'];
      header($header);
      header("Location: $newurl");
      exit();
    }
  }
}

 

Full Settings.php Sample

Here is an example portion of a settings.php with environmental magic on Pantheon

There is an example 404 redirect config, and a redirect for a path part to a subdomain.

Also, a placeholder for 301 redirects.

(warning) note that there are 2 different ways to check the Pantheon environment, here – one for config, the other for web actions like redirects.

Code Block
languagephp
themeRDark
titlesetttings.php
<?php
 
// all other defaults go here
 

/*
* settings for all environements
*/
// Avoid Image resize threshold error
$conf['image_resize_filter_threshold'] = 1000;
// 7.21+ image hack for text-area images
// http://drupal.stackexchange.com/questions/63226/drupal-7-20-image-styles-return-a-url-with-access-denied
$conf['image_allow_insecure_derivatives'] = TRUE;

// if using PHP 5.5 as per https://pantheon.io/docs/articles/drupal/configuring-settings-php/#troubleshooting
ini_set('arg_separator.output', '&');
/**
 * Perform web-only operations on Pantheon like redirects
 * the $_SERVER array will not exist for the drush-cli
 * see http://helpdesk.getpantheon.com/customer/portal/articles/708588
 */
if (isset($_SERVER['PANTHEON_ENVIRONMENT'])) {
  /**
   * Redirect 404 config to the D6 site to hide D7 development
   * REMOVE ME ON LAUNCH
   */
  $conf['redrect_404_search'] = 'http://www.mysite.com/search/apachesolr_search';
  $conf['redirect_404_redirect'] = 'http://www.mysite.com';
  $conf['redirect_404_servers'] = 'http://www.mysite.com';

  if($_SERVER['PANTHEON_ENVIRONMENT']) === 'live') {
    /**/ settings for launching *Featured RedirectEvents
404 config to the D6 site to hide D7 development if($_SERVER['HTTP_HOST'] == 'live-mysite.gotpantheon.com'){
      * REMOVE ME ON LAUNCHheader('HTTP/1.0 301 Moved Permanently');
    */   $conf['redrect_404_search'] = 'header('Location: http://wwwnew.mysite.com/search/apachesolr_search';
  $conf['redirect_404_redirect'] = 'http://www.mysite.com';
  $conf['redirect_404_servers'] = 'http://www.mysite.com';

  if($_SERVER['PANTHEON_ENVIRONMENT'] === 'live') {
    // settings for launching Featured Events'. $_SERVER['REQUEST_URI']);
      exit();
    }
    // Events Launch
    // Redirect all traffic from the "events" subdomain that is not going to
    // an /events/* URI back to www.mysite.com (legacy D6 site).
    if($_SERVER['HTTP_HOST'] === 'live-events.mysite.gotpantheon.com'){       header('HTTP/1.0 301 Moved Permanently');
      header('Location: http://new.mysite.com'.&& !preg_match('/^\/events\/.+/', $_SERVER['REQUEST_URI']) && !preg_match('/^\/event-speaker-details\//', $_SERVER['REQUEST_URI']);
      exit();
    }
    // Events Launch
    // Redirect all traffic from the "events" subdomain that is not going to
    // an /events/* URI back to www.mysite.com (legacy D6 site).]) && !preg_match('/^\/sites\/.+/', $_SERVER['REQUEST_URI']) ) {
      ifheader($_SERVER['HTTP_HOST'] === 'events.mysite.com' && !preg_match('/^\/events\/.+/',/1.0 303 Temporary Redirect');
      header('Location: http://www.mysite.com'. $_SERVER['REQUEST_URI']) && !preg_match('/^\/event-speaker-details\//', $_SERVER['REQUEST_URI']) && !preg_match('/^\/sites\/.+/', ;
      exit();
    }
    // // full launch
    // if (in_array($_SERVER['REQUESTHTTP_URIHOST']), )array(
{    //   header('HTTP/1.0 303 Temporary Redirect');'live-mysite.gotpantheon.com',
    //   'mysite.org',
    //  header('Location: http:// 'www.mysite.comorg'. $_SERVER['REQUEST_URI']);,
    //    exit();'new.mysite.com',
    //  } 'mysite.com',
   // // full))) launch{
    // if  (in_array($_SERVER['HTTP_HOST'], array(header('HTTP/1.0 301 Moved Permanently');
     //   'live-mysite.gotpantheon.com',header('Location: http://www.mysite.com'. $_SERVER['REQUEST_URI']);
    //   'mysite.org',exit();
    // }
 'www.mysite.org',
 }

  //   'new.mysite.com',
if($_SERVER['PANTHEON_ENVIRONMENT'] === 'test') {
   //   'mysite.com',
    // ))) if($_SERVER['HTTP_HOST'] == 'test-mysite.gotpantheon.com') {
    //   header('HTTP/1.0 301 Moved Permanently');
    //   header('Location: http://wwwtest.mysite.com'. $_SERVER['REQUEST_URI']);
    //   exit();
    // }
  }

  if($_SERVER['PANTHEON_ENVIRONMENT'] === 'test') {
 
    }
  }
  if ($_SERVER['HTTPPANTHEON_HOSTENVIRONMENT'] === 'test-mysite.gotpantheon.comdev') {
    // Error reporting
 header('HTTP/1.0 301 Moved Permanently' error_reporting(-1);  // Have PHP complain about header('Location: http://test.mysite.com'. $_SERVER['REQUEST_URI']);
 absolutely everything.
    $conf['error_level'] = 2;  // Show all messages on your screen
    exit(ini_set('display_errors', TRUE);  // These  }
  }lines give you content on WSOD pages.
   if ini_set($_SERVER['PANTHEON_ENVIRONMENT'] === 'dev') {'display_startup_errors', TRUE);
   
    if($_SERVER['HTTP_HOST'] == 'dev-mysite.gotpantheon.com') {
      header('HTTP/1.0 301 Moved Permanently');
      header('Location: http://dev.mysite.com'. $_SERVER['REQUEST_URI']);
      exit();
    }
  }

}
/**
 * Perform web and drush operations on Pantheon
 * see http://helpdesk.getpantheon.com/customer/portal/articles/708588
 */
if (defined('PANTHEON_ENVIRONMENT')) {
  /**
   * Use Redis for caching AND performance settings
   * see http://helpdesk.getpantheon.com/customer/portal/articles/401317-redis
   */
  $conf['redis_client_interface'] = 'PhpRedis';
  $conf['cache_backends'][] = 'sites/all/modules/contrib/redis/redis.autoload.inc';
  $conf['cache_default_class'] = 'Redis_Cache';
  // Make sure that we don't have collisions by prefixing the cache keys per environment
  $conf['cache_prefix'] = array('default' => 'pantheon-redis-' . $_SERVER['PANTHEON_ENVIRONMENT'] );
  // Do not use Redis for cache_form (no performance difference)..
  $conf['cache_class_cache_form'] = 'DrupalDatabaseCache';
  // Don't use Redis for Views cache, has caused some display issues.
  $conf['cache_class_cache_views'] = 'DrupalDatabaseCache';
  $conf['cache_class_cache_formviews_data'] = 'DrupalDatabaseCache';
  // Don't useUse Redis for ViewsDrupal cache, has caused some display issueslocks (semaphore).
  $conf['cache_class_cache_viewslock_inc'] = 'DrupalDatabaseCache';
  $conf['cache_class_cache_views_data'] = 'DrupalDatabaseCache'; 'sites/all/modules/contrib/redis/redis.lock.inc';

  /**
  * Set some configuration settings for DEV, TEST, and LIVE
  */
  // UseCached Redispage forcompression Drupal- locksalways (semaphore)off.
  $conf['lockpage_inccompression'] = 'sites/all/modules/contrib/redis/redis.lock.inc';

  /**
  * Set some configuration settings for DEV, TEST, 0;
  // Minimum cache lifetime - always none.
  $conf['cache_lifetime'] = 0;

  // Drupal caching in TEST and LIVE should mostly */line up
 // Cached page compression - always off.
  $conf['page_compression'] = 0;if (in_array(PANTHEON_ENVIRONMENT, array('test', 'live'))) {
    // MinimumAnonymous cache lifetime - always none.caching
    $conf['cache_lifetime'] = 01;
  }
  // DrupalSome cachingsettings in TEST and LIVEDEV should mostlybe linethe upsame
  if (in_array(PANTHEON_ENVIRONMENT, array('test', 'live'))) {', 'dev'))) {
    // rules or system messages can email users during testing unless we say no
    $conf['reroute_email_enable'] = 1;
    // Anonymous caching Expiration of cached pages - none.
    $conf['page_cache_maximum_age'] = 10;
  }
  // Some settings in TEST and DEV should be the same
  if (in_array(PANTHEON_ENVIRONMENT, array('test', 'dev'))) {
    // rules or system messages can email users during testing unless we say no
    $conf['reroute_email_enable'] = 1if (PANTHEON_ENVIRONMENT == 'live') {
    // Expiration of cached pages - 1 minute.
    $conf['page_cache_maximum_age'] = 60; //900
    $conf['preprocess_css'] = 1;
    $conf['preprocess_js'] = 1;
    // $conf['css_gzip_compression'] = TRUE;
    // Expiration of cached pages - none.
    $conf['pagejs_cachegzip_maximum_agecompression'] = 0TRUE;
  }
  if (PANTHEON_ENVIRONMENT == 'livetest') {
  }
 // Expiration of cached pages - 1 minute.if (PANTHEON_ENVIRONMENT == 'dev') {
    //  $conf['page_cache_maximum_age'] = 60; //900Disable caches for easier debugging
    $conf['preprocess_csscache'] = 10;
    $conf['preprocess_jscss'] = 10;
    // $conf['csspreprocess_gzip_compressionjs'] = TRUE0;
    // $conf['jspage_cache_gzipmaximum_compressionage'] = TRUE;
  }
  if (PANTHEON_ENVIRONMENT == 'test') {
  }
  if (PANTHEON_ENVIRONMENT == 'dev') {0;
 
    // Anonymous caching Have PHP complain about absolutely everything.
    $conf['cacheerror_level'] = 0;2;  // Show all messages on your screen
    $conf['preprocess_css'] = 0;ini_set('display_errors', TRUE);  // These lines give you content on WSOD pages.
    $conf['preprocess_js'] = 0ini_set('display_startup_errors', TRUE);
  }
}
/* perform 301 redirects */
// // print_r($_SERVER);
// if($_SERVER['REQUEST_URI'] == '/path/one') {
//   header('HTTP/1.0 301 Moved Permanently');
//   header('Location: /path/two');
//   exit();
// }
//

/**
 * Terminatur
 *
 * These local settings were generated by terminatur.
 * You may see them if you use Kalastack, Kalabox, Proviso or other local dev
 * tools.
 *
 */
if (isset($_SERVER['KALABOX']) &&  $_SERVER['KALABOX'] === 'on') {
  // DB Array and some common conf.
  $databases['default']['default'] = array(
    'driver' => 'mysql',
    'database' => 'mysite_kala',
    'username' => 'root',
    'password' => 'password',
    'host' => 'localhost',
    'port' => '3306',
    'prefix' => '',
  );
  // Set some common desirable local vars.
  $conf['file_temporary_path'] = '/tmp';
  $conf['file_public_path'] = 'sites/default/files';
  $conf['file_private_path'] = 'sites/default/files/private';
  $conf['reroute_email_enable'] = 1;

  $conf['cache'] = 0;
  $conf['css_gzip_compression'] = FALSE;
  $conf['js_gzip_compression'] = FALSE;
  $conf['preprocess_css'] = 0;
  $conf['preprocess_js'] = 0;
  $conf['site_name'] = 'mysite Local';
  $conf['cron_last'] = '9999999999';
}

...

Here is an example of D6 settings (note Habitat isnt available for D^D6, but you can do module disable/enable through the settings.php:

Code Block
languagephp
themeRDarklanguagephp
if (defined('PANTHEON_ENVIRONMENT')) {
  if (PANTHEON_ENVIRONMENT == 'dev') {
    $conf = array(
      'securepages_enable' => FALSE,
      'securesite_enabled' => '0',
      'preprocess_css' => FALSE,
      'preprocess_js' => FALSE,
      'reroute_email_enable' => 1,
      'fetcher_environment' => 'dev',
    );
  }
  if (PANTHEON_ENVIRONMENT == 'test') {
    $conf = array(
      'securepages_enable' => FALSE,
      'securesite_enabled' => '0',
      'preprocess_css' => FALSE,
      'preprocess_js' => FALSE,
      'reroute_email_enable' => 1,
      'fetcher_environment' => 'test',
    );
  }
  if (PANTHEON_ENVIRONMENT == 'live') {
    $conf = array(
      'securepages_enable' => TRUE,
      'securesite_enabled' => '1',
      'preprocess_css' => TRUE,
      'preprocess_js' => TRUE,
      'fetcher_environment' => 'prod',
    );
  }
}

...