Skip to content

Instantly share code, notes, and snippets.

@PunchRockgroin
Forked from janw-me/env-config.php
Created October 12, 2020 15:35
Show Gist options
  • Save PunchRockgroin/36bb204fd199cc79093419fc956b7a55 to your computer and use it in GitHub Desktop.
Save PunchRockgroin/36bb204fd199cc79093419fc956b7a55 to your computer and use it in GitHub Desktop.

The wp-config.php will get split in seperate files. the wp-config.php and the env-config.php. env-config.php should never be in the Google Drive / git. It's location should be above the public_html not inside it. In wp-config.php the defaults are set, secret data or data that might differ should be in env-config.php

How to

Create the env-config.php above the public_html. Set the constants needed there. Open the wp-config.php and compere it with the template below. Are there constants that are in the original that are not in the template? Are there constants that are different?

The original should be replaced with the template. But with the tweaks needed.

Specific Constants

Auto generated

Constants set by ithemes/wp rocket or other plugins, keep them at the top of the wp-config.php.

// BEGIN iThemes Security - Do not modify or remove this line
// iThemes Security Config Details: 2
define( 'DISALLOW_FILE_EDIT', true ); // Disable File Editor - Security > Settings > WordPress Tweaks > File Editor
define( 'FORCE_SSL_ADMIN', true ); // Redirect All HTTP Page Requests to HTTPS - Security > Settings > Secure Socket Layers (SSL) > SSL for Dashboard
// END iThemes Security - Do not modify or remove this line
define('WP_CACHE', true); // Added by WP Rocket

Keep

The list of ***_KEY constants should be kept in the wp-config.php The table_prefix should also be kept in the wp-config.php

Exceptions

Check extra for the following constants, and set in env-config.php.

// don't keep if not present, it's old and probably can do without. Remove on wp-provider
define('WP_MEMORY_LIMIT', '192M');

// if it's not "utf8mb4" keep it,
define( 'DB_CHARSET', 'utf8' );

Don't touch.

Constant's that should not be touched, let the new wp-config.php take care of it

  • AUTOSAVE_INTERVAL
  • CORE_UPGRADE_SKIP_NEW_BUNDLED
  • DISABLE_WP_CRON
  • DISALLOW_FILE_EDIT
  • DISALLOW_FILE_MODS
  • EMPTY_TRASH_DAYS
  • WP_DEBUG_DISPLAY
  • WP_DEBUG_LOG
  • WP_DEBUG
  • WP_DEFAULT_THEME
  • WP_POST_REVISIONS
  • WP_SITEURL
  • WPLANG
<?php
// Valid values: development, staging and production. To get this value use: wp_get_environment_type()
defined( 'WP_ENVIRONMENT_TYPE' ) or define( 'WP_ENVIRONMENT_TYPE', 'production' );
define('DB_NAME', 'fill in db name');
define('DB_USER', 'fill in username');
define('DB_PASSWORD', 'fill in db password');
define('DB_HOST', 'localhost');
define('WP_HOME', 'http://www.example.nl'); // No trailing slash
<?php
// Check if a enviroment file is defined and include it.
if ( is_file( dirname( __DIR__ ) . '/env-config.php' ) ) include( dirname( __DIR__ ) . '/env-config.php' );
if ( is_file( dirname( __FILE__ ) . '/env-config.php' ) ) include( dirname( __FILE__ ) . '/env-config.php' );
//====================================================================
// Below should only contain the defaults for local development
//====================================================================
// Database
defined( 'DB_NAME' ) or define( 'DB_NAME', 'wp' );
defined( 'DB_USER' ) or define( 'DB_USER', 'wp' );
defined( 'DB_PASSWORD' ) or define( 'DB_PASSWORD', 'wp' );
defined( 'DB_HOST' ) or define( 'DB_HOST', 'localhost' );
// Url
// Url
$http_s = ( isset($_SERVER['HTTPS']) && !empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') ? 'https' : 'http';
defined( 'WP_HOME' ) or define( 'WP_HOME', $http_s . '://example.test' ); // no trailing slash
//====================================================================
// Below should be the same for every enviroment
//====================================================================
$table_prefix = 'rndm_'; // please change with 2-5 random letters/digits
// https://api.wordpress.org/secret-key/1.1/salt
define( 'AUTH_KEY', '************************************************');
define( 'SECURE_AUTH_KEY', '************************************************');
define( 'LOGGED_IN_KEY', '************************************************');
define( 'NONCE_KEY', '************************************************');
define( 'AUTH_SALT', '************************************************');
define( 'SECURE_AUTH_SALT', '************************************************');
define( 'LOGGED_IN_SALT', '************************************************');
define( 'NONCE_SALT', '************************************************');
// Multisite
defined( 'WP_ALLOW_MULTISITE' ) or define( 'WP_ALLOW_MULTISITE', false );
/* // Unquote for multisites
defined( 'MULTISITE' ) or define( 'MULTISITE', true );
defined( 'SUBDOMAIN_INSTALL' ) or define( 'SUBDOMAIN_INSTALL', false );
defined( 'DOMAIN_CURRENT_SITE' ) or define( 'DOMAIN_CURRENT_SITE', 'example.com' ); // no `http://` see env-config.php
defined( 'PATH_CURRENT_SITE' ) or define( 'PATH_CURRENT_SITE', '/' );
defined( 'SITE_ID_CURRENT_SITE' ) or define( 'SITE_ID_CURRENT_SITE', 1 );
defined( 'BLOG_ID_CURRENT_SITE' ) or define( 'BLOG_ID_CURRENT_SITE', 1 );
/**/
//====================================================================
// That's all, stop editing! Happy blogging.
//====================================================================
// URL and paths
defined( 'WP_SITEURL' ) or define( 'WP_SITEURL', WP_HOME );
defined( 'WP_CONTENT_DIR' ) or define( 'WP_CONTENT_DIR', dirname( __FILE__ ) . '/wp-content' );
defined( 'WP_CONTENT_URL' ) or define( 'WP_CONTENT_URL', WP_HOME . '/wp-content' );
defined( 'PLUGINDIR' ) or define( 'PLUGINDIR', 'wp-content/plugins' ); // Relative to ABSPATH. For back compat.
defined( 'MUPLUGINDIR' ) or define( 'MUPLUGINDIR', 'wp-content/mu-plugins' ); // Relative to ABSPATH. For back compat.
// DB
defined( 'DB_CHARSET' ) or define( 'DB_CHARSET', 'utf8mb4' );
defined( 'DB_COLLATE' ) or define( 'DB_COLLATE', '' );
// Minor tweaks
defined( 'AUTOSAVE_INTERVAL' ) or define( 'AUTOSAVE_INTERVAL', 300 ); // autosave every 300 seconds
defined( 'WP_POST_REVISIONS' ) or define( 'WP_POST_REVISIONS', 10 ); // 10 post revisions
defined( 'DISALLOW_FILE_EDIT' ) or define( 'DISALLOW_FILE_EDIT', true ); // don't allow to edit files in the wp-admin.
defined( 'DISALLOW_FILE_MODS' ) or define( 'DISALLOW_FILE_MODS', false ); // don't alllow installing/updating of plugins.
defined( 'EMPTY_TRASH_DAYS' ) or define( 'EMPTY_TRASH_DAYS', 30 );
defined( 'DISABLE_WP_CRON' ) or define( 'DISABLE_WP_CRON', true ); // disable the cron executed by visiting webpages
defined( 'CORE_UPGRADE_SKIP_NEW_BUNDLED' ) or define( 'CORE_UPGRADE_SKIP_NEW_BUNDLED', true); // don't install default themes/plugins on update
defined( 'WP_DEFAULT_THEME' ) or define( 'WP_DEFAULT_THEME', 'genesis'); // Set Genesis as default theme
// Debug defaults
if ( ( defined( 'WP_ENVIRONMENT_TYPE' ) && WP_ENVIRONMENT_TYPE === 'development' ) ) {
defined( 'WP_DEBUG_DISPLAY' ) or define( 'WP_DEBUG_DISPLAY', true );
defined( 'WP_DEBUG' ) or define( 'WP_DEBUG', true );
} else {
// log errors when it's not a development server
defined( 'WP_DEBUG_LOG' ) or define( 'WP_DEBUG_LOG', WP_CONTENT_DIR . '/debug.log' );
defined( 'WP_DEBUG_DISPLAY' ) or define( 'WP_DEBUG_DISPLAY', false );
defined( 'WP_DEBUG' ) or define( 'WP_DEBUG', true ); // so it's logging errors.
}
/** Absolute path to the WordPress directory. */
if ( ! defined( 'ABSPATH' ) ) {
defined( 'ABSPATH' ) or define( 'ABSPATH', dirname( __FILE__ ) . '/' );
}
/** Sets up WordPress vars and included files. */
require_once( ABSPATH . 'wp-settings.php' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment