WP-CLI on a cloned local Pantheon WordPress

Pantheon is a great system for spinning up Wordpress Installs. Except that you can’t use WP-CLI locally on them. You’ll receive something like this:

[05-Aug-2014 14:30:45 UTC] PHP Fatal error: Cannot redeclare wp_unregister_GLOBALS() (previously declared in /Applications/MAMP/htdocs/lookey/wp-includes/load.php:17) in /Applications/MAMP/htdocs/lookey/wp-includes/load.php on line 32

Virtually impossible to debug, but easy to fix.

Pantheon is a great system for spinning up WordPress Installs. Except that you can’t use WP-CLI locally on them. You’ll receive something like this:

[05-Aug-2014 14:30:45 UTC] PHP Fatal error: Cannot redeclare wp_unregister_GLOBALS() (previously declared in /Applications/MAMP/htdocs/lookey/wp-includes/load.php:17) in /Applications/MAMP/htdocs/lookey/wp-includes/load.php on line 32

Virtually impossible to debug, but easy to fix.

The trick is that WP-CLI tries to automatically strip out the wp-settings.php from wp-config.php. This fails because locally, it is loaded in wp-config-local.php. Rather adding all of the logic into wp-config.php, a quick fix is to:

change line 90 of wp-config-local.php from this:

require_once(ABSPATH . 'wp-settings.php');

to this:

if ( ! defined( 'WP_CLI' ) ) require_once(ABSPATH . 'wp-settings.php');

and it should be fixed!

Before:

[05-Aug-2014 14:30:45 UTC] PHP Fatal error:  Cannot redeclare wp_unregister_GLOBALS() (previously declared in /Applications/MAMP/htdocs/lookey/wp-includes/load.php:17) in /Applications/MAMP/htdocs/lookey/wp-includes/load.php on line 32
[05-Aug-2014 14:30:45 UTC] PHP Stack trace:
[05-Aug-2014 14:30:45 UTC] PHP   1. {main}() /usr/local/bin/wp:0
[05-Aug-2014 14:30:45 UTC] PHP   2. include() /usr/local/bin/wp:4
[05-Aug-2014 14:30:45 UTC] PHP   3. include() phar:///usr/local/bin/wp/php/boot-phar.php:5
[05-Aug-2014 14:30:45 UTC] PHP   4. require() phar:///usr/local/bin/wp/php/wp-cli.php:26

After:
wp-cli-pantheon-local

Original fix figured by Rarst here.