How to Transfer + Clean WPEngine Backup Zip for Local Installation

If you have ever tried to do some tests on a local installation with a WordPress site hosted on WPEngine you may have found that it doesn’t always work right out of the box. Sometimes you just need to use XDebug with PHPStorm in a local troubleshooting environment to efficiently debug a site so a local install is necessary.

This tutorial will show you which files and folders to remove from the WPEngine backup zip that you can generate from their dashboard in My WPEngine as well as cleaning up the wp-config.php constants.

When you are done you will be able to use the WPEngine backup on Local by Flywheel, MAMP, docker or whatever your preferred local WordPress installation method is.

Thanks to Codeable I have had the privilege of working with many WPEngine customers. I have had to do use local installations for advanced debugging so often that I have also written a bash script for automatically cleaning the WPEngine variables and constants along with the mu-plugins which you’ll find at the bottom of this post.

There are a few areas that are a good idea to cleanup like the wp-config.php and the mu-plugins folder, let’s start!

Prepare and Clean WPEngine Backup Zip for Local Installation

Let’s clean up the WPEngine mu-plugins first, these are the files and folders you will want to remove

wp-content/mu-plugins/force-strong-passwords
wp-content/mu-plugins/slt-force-strong-passwords.php
wp-content/mu-plugins/stop-long-comments.php
wp-content/mu-plugins/mu-plugin.php
wp-content/mu-plugins/wpengine-common
wp-content/object-cache.php
wp-content/advanced-cache.php

The next thing we are going to do is clean up the wp-config.php file since WPEngine add quite a lot of variables in here that helps sites interface with their platform.

Here is a sample wp-config.php from a WPEngine backup, all of the lines to remove are highlighted in red

<?php

/**
 * The base configuration for WordPress
 *
 * The wp-config.php creation script uses this file during the
 * installation. You don't have to use the web site, you can
 * copy this file to "wp-config.php" and fill in the values.
 *
 * This file contains the following configurations:
 *
 * * MySQL settings
 * * Secret keys
 * * Database table prefix
 * * ABSPATH
 *
 * @link https://codex.wordpress.org/Editing_wp-config.php
 *
 * @package WordPress
 */

// ** MySQL settings ** //
/** The name of the database for WordPress */
define( 'DB_NAME', 'wp_example' );

/** MySQL database username */
define( 'DB_USER', 'example' );

/** MySQL database password */
define( 'DB_PASSWORD', 'yfV7WLd5ejsjLdI1ckRR' );

/** MySQL hostname */
define( 'DB_HOST', '127.0.0.1' );

/** Database Charset to use in creating database tables. */
define( 'DB_CHARSET', 'utf8' );

/** The Database Collate type. Don't change this if in doubt. */
define( 'DB_COLLATE', 'utf8_unicode_ci' );

/**
 * Authentication Unique Keys and Salts.
 *
 * Change these to different unique phrases!
 * You can generate these using the {@link https://api.wordpress.org/secret-key/1.1/salt/ WordPress.org secret-key service}
 * You can change these at any point in time to invalidate all existing cookies. This will force all users to have to log in again.
 *
 * @since 2.6.0
 */
define( 'AUTH_KEY', 'wP!Q@$D(1aoZl]4+qd1`p@}!)r9l@__B<ee`Ou.lq:tMd m88@rOGb8S)M9aY7i-' );
define( 'SECURE_AUTH_KEY', 'OZ~n7-!{*9m~sX?mx5 ]4>nW)+[x/L//}~D[sfa]F@_aW?CvXuqNB&$8,l;@)U|}' );
define( 'LOGGED_IN_KEY', 'X;G,<RiE._9~r-V^kAY/Nej+=efy+z0F&eU@VM1eOl.)4.OgfNZtck&>|MegPMFi' );
define( 'NONCE_KEY', 't-EB$7,/by|PjpeXA+n$sNr#W],-)R`>&XkI-nHi_D`qBk)qWsROlU0F-|C> yeU' );
define( 'AUTH_SALT',        '/-,IybCeESN/UYl2i>.r#7~_=Ga<By0!!%M=0HECyWa)<{?eI]4Wlwp&s1bZ)*DF' );
define( 'SECURE_AUTH_SALT', 'xoUL&8v]`M)oE%j5:=Q}?}TXbd/9a<:}qU@>A.?muG|vtRK/o<2V-jc>SnFS+tLe' );
define( 'LOGGED_IN_SALT',   'q28I:%Y/@ub=5nsRt{*^krmA~3{-}`kpz`iUdv:<_LUdClg=6SISMG:JdRY ke<6' );
define( 'NONCE_SALT',       'GVy{u`93E!Kjv-0DaHn(z!VSP^Vo;cq]//TW-lTLLXSf@7rUF[C.Y5?|~<{zYMjJ' );

/**
 * WordPress Database Table prefix.
 *
 * You can have multiple installations in one database if you give each
 * a unique prefix. Only numbers, letters, and underscores please!
 */
$table_prefix = 'wp_';


define(' WP_SITEURL','https://example.com' );

define(' WP_HOME','https://example.com' );

define( 'WPE_APIKEY', 'XXXXXabcdd05c9a9426f7c4b4e0716785732b0a6' );

define( 'WPE_FORCE_SSL_LOGIN', false );

define( 'WPE_EXTERNAL_URL', false );

define( 'FORCE_SSL_LOGIN', false );

define( 'DB_HOST_SLAVE', '127.0.0.1' );

define( 'PWP_NAME', 'example' );

define( 'WP_CACHE', TRUE );

define( 'WP_AUTO_UPDATE_CORE', false );

define( 'FS_METHOD', 'direct' );

define( 'FS_CHMOD_DIR', 0775 );

define( 'FS_CHMOD_FILE', 0664 );

define( 'PWP_ROOT_DIR', '/nas/wp' );

define( 'WPE_CLUSTER_ID', '111111' );

define( 'WPE_CLUSTER_TYPE', 'pod' );

define( 'WPE_ISP', true );

define( 'WPE_BPOD', false );

define( 'WPE_RO_FILESYSTEM', false );

define( 'WPE_LARGEFS_BUCKET', 'largefs.wpengine' );

define( 'WPE_SFTP_PORT', 2222 );

define( 'WPE_LBMASTER_IP', '' );

define( 'WPE_CDN_DISABLE_ALLOWED', false );

define( 'DISALLOW_FILE_MODS', FALSE );

define( 'DISALLOW_FILE_EDIT', FALSE );

define( 'DISABLE_WP_CRON', false );

/*SSLSTART*/ if ( isset($_SERVER['HTTP_X_WPE_SSL']) && $_SERVER['HTTP_X_WPE_SSL'] ) $_SERVER['HTTPS'] = 'on'; /*SSLEND*/

define( 'WP_POST_REVISIONS', FALSE );

define( 'WPE_WHITELABEL', 'wpengine' );

define( 'WP_TURN_OFF_ADMIN_BAR', false );

define( 'WPE_BETA_TESTER', false );

umask(0002);

$wpe_cdn_uris=array ( );

$wpe_no_cdn_uris=array ( );

$wpe_content_regexs=array ( );

$wpe_all_domains=array ( 0 => 'example.com', 1 => 'example.wpengine.com', 2 => 'www.example.com', );

$wpe_varnish_servers=array ( 0 => 'pod-111111', );

$wpe_special_ips=array ( 0 => '1.1.1.1', );

$wpe_ec_servers=array ( );

$wpe_largefs=array ( );

$wpe_netdna_domains=array ( );

$wpe_netdna_domains_secure=array ( );

$wpe_netdna_push_domains=array ( );

$wpe_domain_mappings=array ( );

$memcached_servers=array ( );

define( 'WPLANG', '' );

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

#define( 'WPE_MONITOR_ADMIN_AJAX', true );


/** Absolute path to the WordPress directory. */
if ( ! defined( 'ABSPATH' ) )
        define( 'ABSPATH', dirname( __FILE__ ) . '/' );

/** Sets up WordPress vars and included files. */
require_once ABSPATH . 'wp-settings.php';

$_wpe_preamble_path = null; if(false){}

Let’s see what it looks like all cleaned up

<?php

/**
 * The base configuration for WordPress
 *
 * The wp-config.php creation script uses this file during the
 * installation. You don't have to use the web site, you can
 * copy this file to "wp-config.php" and fill in the values.
 *
 * This file contains the following configurations:
 *
 * * MySQL settings
 * * Secret keys
 * * Database table prefix
 * * ABSPATH
 *
 * @link https://codex.wordpress.org/Editing_wp-config.php
 *
 * @package WordPress
 */

// ** MySQL settings ** //
/** The name of the database for WordPress */
define( 'DB_NAME', 'wp_example' );

/** MySQL database username */
define( 'DB_USER', 'example' );

/** MySQL database password */
define( 'DB_PASSWORD', 'yfV7WLd5ejsjLdI1ckRR' );

/** MySQL hostname */
define( 'DB_HOST', '127.0.0.1' );

/** Database Charset to use in creating database tables. */
define( 'DB_CHARSET', 'utf8' );

/** The Database Collate type. Don't change this if in doubt. */
define( 'DB_COLLATE', 'utf8_unicode_ci' );

/**
 * Authentication Unique Keys and Salts.
 *
 * Change these to different unique phrases!
 * You can generate these using the {@link https://api.wordpress.org/secret-key/1.1/salt/ WordPress.org secret-key service}
 * You can change these at any point in time to invalidate all existing cookies. This will force all users to have to log in again.
 *
 * @since 2.6.0
 */
define( 'AUTH_KEY', 'wP!Q@$D(1aoZl]4+qd1`p@}!)r9l@__B<ee`Ou.lq:tMd m88@rOGb8S)M9aY7i-' );
define( 'SECURE_AUTH_KEY', 'OZ~n7-!{*9m~sX?mx5 ]4>nW)+[x/L//}~D[sfa]F@_aW?CvXuqNB&$8,l;@)U|}' );
define( 'LOGGED_IN_KEY', 'X;G,<RiE._9~r-V^kAY/Nej+=efy+z0F&eU@VM1eOl.)4.OgfNZtck&>|MegPMFi' );
define( 'NONCE_KEY', 't-EB$7,/by|PjpeXA+n$sNr#W],-)R`>&XkI-nHi_D`qBk)qWsROlU0F-|C> yeU' );
define( 'AUTH_SALT',        '/-,IybCeESN/UYl2i>.r#7~_=Ga<By0!!%M=0HECyWa)<{?eI]4Wlwp&s1bZ)*DF' );
define( 'SECURE_AUTH_SALT', 'xoUL&8v]`M)oE%j5:=Q}?}TXbd/9a<:}qU@>A.?muG|vtRK/o<2V-jc>SnFS+tLe' );
define( 'LOGGED_IN_SALT',   'q28I:%Y/@ub=5nsRt{*^krmA~3{-}`kpz`iUdv:<_LUdClg=6SISMG:JdRY ke<6' );
define( 'NONCE_SALT',       'GVy{u`93E!Kjv-0DaHn(z!VSP^Vo;cq]//TW-lTLLXSf@7rUF[C.Y5?|~<{zYMjJ' );

/**
 * WordPress Database Table prefix.
 *
 * You can have multiple installations in one database if you give each
 * a unique prefix. Only numbers, letters, and underscores please!
 */
$table_prefix = 'wp_';

define( 'FS_METHOD', 'direct' );

define( 'FS_CHMOD_DIR', 0775 );

define( 'FS_CHMOD_FILE', 0664 );

define( 'WPLANG','' );
/* That's all, stop editing! Happy blogging. */

/** Absolute path to the WordPress directory. */
if ( ! defined( 'ABSPATH' ) )
        define( 'ABSPATH', dirname( __FILE__ ) . '/' );

/** Sets up WordPress vars and included files. */
require_once ABSPATH . 'wp-settings.php';

Bash Script for Cleaning WPEngine Backup

I wrote this Linux bash script to remove all of the wp-config.phpse automatically for you :).

You should run this in the root of the WordPress installation that contains the wp-config.php file.

#!/usr/bin/env bash
# Purpose: Cleans up WPEngine variables, constants and mu-plugins
# Author: Mike from WP Bullet
# defines the path to wp-config.php
WPCONFIGPATH=wp-config.php

# back up the wp-config.php just in case
cp ${WPCONFIGPATH} ${WPCONFIGPATH}.wpengine
# replace 127.0.0.1 to avoid ERROR 1130 (HY000): Host '127.0.0.1' is not allowed to connect to this MariaDB server
sed -i "s#127.0.0.1#localhost#g" ${WPCONFIGPATH}

# remove the DB_HOST_SLAVE entry
sed -i "/define( 'DB_HOST_SLAVE'/d" ${WPCONFIGPATH}

# remove any hardcoded WP_SITEURL and WP_HOME
sed -i '/WP_SITEURL/d' ${WPCONFIGPATH}
sed -i '/WP_HOME/d' ${WPCONFIGPATH}

# clean up WPE variables from wp-config.php
sed -i '/WP_SITEURL/d' ${WPCONFIGPATH}
sed -i '/WP_HOME/d' ${WPCONFIGPATH}
sed -i '/wpe/d' ${WPCONFIGPATH}
sed -i '/WPE/d' ${WPCONFIGPATH}
sed -i '/PWP/d' ${WPCONFIGPATH}
sed -i '/memcached_servers/d' ${WPCONFIGPATH}
sed -i '/WP Engine/d' ${WPCONFIGPATH}
sed -i "/define( 'WP_CACHE'/d" ${WPCONFIGPATH}
sed -i "/define( 'DISABLE_WP_CRON'/d" ${WPCONFIGPATH}
sed -i "/define( 'FORCE_SSL_LOGIN'/d" ${WPCONFIGPATH}
sed -i "/define( 'WP_TURN_OFF_ADMIN_BAR'/d" ${WPCONFIGPATH}
sed -i "/define( 'WP_AUTO_UPDATE_CORE'/d" ${WPCONFIGPATH}
sed -i "/define( 'DISALLOW_FILE_MODS'/d" ${WPCONFIGPATH}
sed -i "/define( 'DISALLOW_FILE_EDIT'/d" ${WPCONFIGPATH}
sed -i "/define( 'WP_POST_REVISIONS'/d" ${WPCONFIGPATH}
sed -i "/umask(0002)/d" ${WPCONFIGPATH}

# remove the empty blank lines https://stackoverflow.com/questions/4521162/can-i-use-the-sed-command-to-replace-multiple-empty-line-with-one-empty-line
sed -i '/^$/N;/^\n$/D' ${WPCONFIGPATH}

# remove the mu-plugins
rm -rf wp-content/mu-plugins/force-strong-passwords
rm -rf wp-content/mu-plugins/slt-force-strong-passwords.php
rm -rf wp-content/mu-plugins/stop-long-comments.php
rm -rf wp-content/mu-plugins/mu-plugin.php
rm -rf wp-content/mu-plugins/wpengine-common
rm -rf wp-content/object-cache.php

Here is another version that doesn’t care about spaces in some of the variables

#!/usr/bin/env bash
# Purpose: Cleans up WPEngine variables, constants and mu-plugins
# Author: Mike from WP Bullet
# defines the path to wp-config.php
WPCONFIGPATH=wp-config.php

# back up the wp-config.php just in case
cp ${WPCONFIGPATH} ${WPCONFIGPATH}.wpengine
# replace 127.0.0.1 to avoid ERROR 1130 (HY000): Host '127.0.0.1' is not allowed to connect to this MariaDB server
sed -i "s#127.0.0.1#localhost#g" ${WPCONFIGPATH}

# remove the DB_HOST_SLAVE entry
sed -i "/'DB_HOST_SLAVE'/d" ${WPCONFIGPATH}

# remove any hardcoded WP_SITEURL and WP_HOME
sed -i '/WP_SITEURL/d' ${WPCONFIGPATH}
sed -i '/WP_HOME/d' ${WPCONFIGPATH}

# clean up WPE variables from wp-config.php
sed -i '/WP_SITEURL/d' ${WPCONFIGPATH}
sed -i '/WP_HOME/d' ${WPCONFIGPATH}
sed -i '/wpe/d' ${WPCONFIGPATH}
sed -i '/WPE/d' ${WPCONFIGPATH}
sed -i '/PWP/d' ${WPCONFIGPATH}
sed -i '/memcached_servers/d' ${WPCONFIGPATH}
sed -i '/WP Engine/d' ${WPCONFIGPATH}
sed -i "/'WP_CACHE'/d" ${WPCONFIGPATH}
sed -i "/'DISABLE_WP_CRON'/d" ${WPCONFIGPATH}
sed -i "/'FORCE_SSL_LOGIN'/d" ${WPCONFIGPATH}
sed -i "/'WP_TURN_OFF_ADMIN_BAR'/d" ${WPCONFIGPATH}
sed -i "/'WP_AUTO_UPDATE_CORE'/d" ${WPCONFIGPATH}
sed -i "/'DISALLOW_FILE_MODS'/d" ${WPCONFIGPATH}
sed -i "/'DISALLOW_FILE_EDIT'/d" ${WPCONFIGPATH}
sed -i "/'WP_POST_REVISIONS'/d" ${WPCONFIGPATH}
sed -i "/umask(0002)/d" ${WPCONFIGPATH}

# remove the empty blank lines https://stackoverflow.com/questions/4521162/can-i-use-the-sed-command-to-replace-multiple-empty-line-with-one-empty-line
sed -i '/^$/N;/^\n$/D' ${WPCONFIGPATH}

# remove the mu-plugins
rm -rf wp-content/mu-plugins/force-strong-passwords
rm -rf wp-content/mu-plugins/slt-force-strong-passwords.php
rm -rf wp-content/mu-plugins/stop-long-comments.php
rm -rf wp-content/mu-plugins/mu-plugin.php
rm -rf wp-content/mu-plugins/wpengine-common
rm -rf wp-content/object-cache.php

Sources

Removing empty lines with sed
XML Escaper

1 thought on “How to Transfer + Clean WPEngine Backup Zip for Local Installation”

Comments are closed.