diff --git a/config/config.dev.php b/config/config.dev.php index 562ff9d..dd55fae 100644 --- a/config/config.dev.php +++ b/config/config.dev.php @@ -2,22 +2,30 @@ /** * Development config overrides & db credentials - * + * * Our database credentials and any environment-specific overrides - * + * * @package Focus Lab Master Config - * @version 1.1.1 + * @version 2.2.0 * @author Focus Lab, LLC */ -$env_db['hostname'] = 'localhost'; -$env_db['username'] = ''; -$env_db['password'] = ''; -$env_db['database'] = ''; +$env_config['database'] = array ( + 'expressionengine' => array ( + 'hostname' => 'localhost', + 'username' => '', + 'password' => '', + 'database' => '', + 'dbdriver' => 'mysqli', + 'dbprefix' => 'exp_', + 'pconnect' => FALSE + ), +); -$env_config['webmaster_email'] = 'dev@domain.com'; +// Local testing email address +$env_config['webmaster_email'] = ''; -/* End of file config.dev.php */ -/* Location: ./config/config.dev.php */ \ No newline at end of file +/* End of file config.local.php */ +/* Location: ./config/config.local.php */ diff --git a/config/config.env.php b/config/config.env.php index 8513e6c..e26b7a4 100644 --- a/config/config.env.php +++ b/config/config.env.php @@ -2,44 +2,53 @@ /** * Environment Declaration - * + * * This switch statement sets our environment. The environment is used primarily * in our custom config file setup. It is also used, however, in the front-end * index.php file and the back-end admin.php file to set the debug mode - * + * * @package Focus Lab Master Config - * @version 1.1.1 + * @version 2.2.0 * @author Focus Lab, LLC */ if ( ! defined('ENV')) { + $production = 'domain.com'; + $staging = 'staging.domain.com'; + $development = 'dev.domain.com'; + $local = 'localhost'; + switch (strtolower($_SERVER['HTTP_HOST'])) { - case 'domain.com' : + case $production: define('ENV', 'prod'); define('ENV_FULL', 'Production'); define('ENV_DEBUG', FALSE); + define('ENV_DOMAIN', $production); break; - - case 'staging.domain.com' : + + case $staging: define('ENV', 'stage'); define('ENV_FULL', 'Staging'); define('ENV_DEBUG', FALSE); + define('ENV_DOMAIN', $staging); break; - - case 'dev.domain.com' : + + case $development: define('ENV', 'dev'); define('ENV_FULL', 'Development'); define('ENV_DEBUG', TRUE); + define('ENV_DOMAIN', $development); break; - default : + default: define('ENV', 'local'); define('ENV_FULL', 'Local'); define('ENV_DEBUG', TRUE); + define('ENV_DOMAIN', $local); break; } } /* End of file config.env.php */ -/* Location: ./config/config.env.php */ \ No newline at end of file +/* Location: ./config/config.env.php */ diff --git a/config/config.local.php b/config/config.local.php index c3c6642..0ae2531 100644 --- a/config/config.local.php +++ b/config/config.local.php @@ -2,37 +2,31 @@ /** * Local config overrides & db credentials - * + * * Our database credentials and any environment-specific overrides * This file should be specific to each developer and not tracked in Git - * + * * @package Focus Lab Master Config - * @version 1.1.1 + * @version 2.2.0 * @author Focus Lab, LLC */ - -// Local db -$env_db['hostname'] = 'localhost'; -$env_db['username'] = ''; -$env_db['password'] = ''; -$env_db['database'] = ''; - -/** - * Remote db - typically a shared development database - * - * Putting this below the local settings allows us to easily uncomment the - * lines to connect to a secondary connection, overriding the first settings - */ -// $env_db['hostname'] = 'domain.com'; -// $env_db['username'] = ''; -// $env_db['password'] = ''; -// $env_db['database'] = ''; +$env_config['database'] = array ( + 'expressionengine' => array ( + 'hostname' => 'localhost', + 'username' => '', + 'password' => '', + 'database' => '', + 'dbdriver' => 'mysqli', + 'dbprefix' => 'exp_', + 'pconnect' => FALSE + ), +); // Local testing email address -$env_config['webmaster_email'] = 'me@domain.com'; +$env_config['webmaster_email'] = ''; /* End of file config.local.php */ -/* Location: ./config/config.local.php */ \ No newline at end of file +/* Location: ./config/config.local.php */ diff --git a/config/config.master.php b/config/config.master.php index aefb87f..74cbc87 100644 --- a/config/config.master.php +++ b/config/config.master.php @@ -2,28 +2,28 @@ /** * Focus Lab, LLC Master Config - * + * * This is the master config file for our ExpressionEngine sites * The settings will contain database credentials and numerous "config overrides" * used throughout the site. This file is used as first point of configuration * but there are environment-specific files as well. The idea is that the environment * config files contain config overrides that are specific to a single environment. - * + * * Some config settings are used in multiple (but not all) environments. You will * see the use of conditionals around the ENV constant in this file. This constant is * defined in ./config/config.env.php - * + * * All config files are stored in the ./config/ directory and this master file is "required" * in system/expressionengine/config/config.php and system/expressionengine/config/database.php - * + * * require $_SERVER['DOCUMENT_ROOT'] . '/../config/config.master.php'; - * + * * This config setup is a combination of inspiration from Matt Weinberg and Leevi Graham * @link http://eeinsider.com/articles/multi-server-setup-for-ee-2/ * @link http://ee-garage.com/nsm-config-bootstrap - * + * * @package Focus Lab Master Config - * @version 1.1.1 + * @version 2.1.1 * @author Focus Lab, LLC * @see https://github.com/focuslabllc/ee-master-config */ @@ -33,7 +33,7 @@ // already been loaded in index.php or admin.php if ( ! defined('ENV')) { - require 'config.env.php'; + require 'config.env.php'; } @@ -41,56 +41,23 @@ $env_db = $env_config = $env_global = $master_global = array(); -/** - * Database override magic - * - * If this equates to TRUE then we're in the database.php file - * We don't want these settings bothered with in our config.php file - */ -if (isset($db['expressionengine'])) -{ - /** - * Load our environment-specific config file - * which contains our database credentials - * - * @see config/config.local.php - * @see config/config.dev.php - * @see config/config.stage.php - * @see config/config.prod.php - */ - require 'config.' . ENV . '.php'; - - // Dynamically set the cache path (Shouldn't this be done by default? Who moves the cache path?) - $env_db['cachedir'] = APPPATH . 'cache/'; - - // Merge our database setting arrays - $db['expressionengine'] = array_merge($db['expressionengine'], $env_db); - - // No need to have this variable accessible for the rest of the app - unset($env_db); -} -// End if (isset($db['expressionengine'])) {} - - - /** * Config override magic - * + * * If this equates to TRUE then we're in the config.php file - * We don't want these settings bothered with in our database.php file */ if (isset($config)) { /** * Dynamic path settings - * + * * Make it easy to run the site in multiple environments and not have to switch up * path settings in the database after each migration * As inspired by Matt Weinberg: http://eeinsider.com/articles/multi-server-setup-for-ee-2/ */ $protocol = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? 'https://' : 'http://'; - $base_url = $protocol . $_SERVER['HTTP_HOST']; + $base_url = $protocol . ENV_DOMAIN; $base_path = $_SERVER['DOCUMENT_ROOT']; $system_folder = APPPATH . '../'; $images_folder = 'images'; @@ -121,7 +88,7 @@ /** * Custom upload directory paths - * + * * The array keys must match the ID from exp_upload_prefs */ // $env_config['upload_preferences'] = array( @@ -140,24 +107,23 @@ /** * Template settings - * + * * Working locally we want to reference our template files. * In staging and production we do not use flat files (for ever-so-slightly better performance) * This approach requires that we synchronize templates after each deployment of template changes - * + * * For the distributed Focus Lab, LLC Master Config file this is commented out * You can enable this "feature" by uncommenting the second 'save_tmpl_files' line */ $env_config['save_tmpl_files'] = 'y'; // $env_config['save_tmpl_files'] = (ENV == 'prod') ? 'n' : 'y'; - $env_config['tmpl_file_basepath'] = $base_path . '/../templates'; - $env_config['hidden_template_indicator'] = '_'; + $env_config['hidden_template_indicator'] = '_'; /** * Debugging settings - * + * * These settings are helpful to have in one place * for debugging purposes */ @@ -170,7 +136,7 @@ $env_config['template_debugging'] = (ENV_DEBUG) ? 'y' : 'n' ; /** * Set debug to '2' if we're in dev mode, otherwise just '1' - * + * * 0: no PHP/SQL errors shown * 1: Errors shown to Super Admins * 2: Errors shown to everyone @@ -181,7 +147,7 @@ /** * Tracking & Performance settings - * + * * These settings may impact what happens on certain page loads * and turning them off could help with performance in general */ @@ -200,7 +166,7 @@ /** * 3rd Party Add-on config items as needed */ - + @@ -226,7 +192,7 @@ /** * Load our environment-specific config file * May contain override values from similar above settings - * + * * @see config/config.local.php * @see config/config.dev.php * @see config/config.stage.php @@ -239,7 +205,7 @@ /** * Setup our template-level global variables - * + * * As inspired by NSM Bootstrap Config * @see http://ee-garage.com/nsm-config-bootstrap */ @@ -248,7 +214,7 @@ { $assign_to_config['global_vars'] = array(); } - + // Start our array with environment variables. This gives us {global:env} and {global:env_full} tags for our templates. $master_global = array( 'global:env' => ENV, @@ -259,17 +225,17 @@ /** * Merge arrays to form final datasets - * + * * We've created our base config and global key->value stores * We've also included the environment-specific arrays now * Here we'll merge the arrays to create our final array dataset which * respects "most recent data" first if any keys are duplicated - * + * * This is how our environment settings are "king" over any defaults */ $assign_to_config['global_vars'] = array_merge($assign_to_config['global_vars'], $master_global, $env_global); // global var arrays $config = array_merge($config, $env_config); // config setting arrays - + } // End if (isset($config)) {} diff --git a/config/config.prod.php b/config/config.prod.php index 4dcc2bd..8292f94 100644 --- a/config/config.prod.php +++ b/config/config.prod.php @@ -2,22 +2,29 @@ /** * Production config overrides & db credentials - * + * * Our database credentials and any environment-specific overrides - * + * * @package Focus Lab Master Config - * @version 1.1.1 + * @version 2.2.0 * @author Focus Lab, LLC */ -$env_db['hostname'] = 'localhost'; -$env_db['username'] = ''; -$env_db['password'] = ''; -$env_db['database'] = ''; +$env_config['database'] = array ( + 'expressionengine' => array ( + 'hostname' => 'localhost', + 'username' => '', + 'password' => '', + 'database' => '', + 'dbdriver' => 'mysqli', + 'dbprefix' => 'exp_', + 'pconnect' => FALSE + ), +); // Sample global variable for Production only // Can be used in templates like "{global:google_analytics}" $env_global['global:google_analytics'] = 'UA-XXXXXXX-XX'; -/* End of file config.prod.php */ -/* Location: ./config/config.prod.php */ \ No newline at end of file +/* End of file config.local.php */ +/* Location: ./config/config.local.php */ diff --git a/config/config.stage.php b/config/config.stage.php index bf5fb21..63700d4 100644 --- a/config/config.stage.php +++ b/config/config.stage.php @@ -2,19 +2,30 @@ /** * Staging config overrides & db credentials - * + * * Our database credentials and any environment-specific overrides - * + * * @package Focus Lab Master Config - * @version 1.1.1 + * @version 2.2.0 * @author Focus Lab, LLC */ -$env_db['hostname'] = 'localhost'; -$env_db['username'] = ''; -$env_db['password'] = ''; -$env_db['database'] = ''; +$env_config['database'] = array ( + 'expressionengine' => array ( + 'hostname' => 'localhost', + 'username' => '', + 'password' => '', + 'database' => '', + 'dbdriver' => 'mysqli', + 'dbprefix' => 'exp_', + 'pconnect' => FALSE + ), +); -/* End of file config.stage.php */ -/* Location: ./config/config.stage.php */ \ No newline at end of file +// Local testing email address +$env_config['webmaster_email'] = ''; + + +/* End of file config.local.php */ +/* Location: ./config/config.local.php */ diff --git a/readme.textile b/readme.textile index 7278b5c..3044ecb 100644 --- a/readme.textile +++ b/readme.textile @@ -1,6 +1,6 @@ -h1. Focus Lab LLC's EE Master Config +h1. Focus Lab LLC's EE Master Config (EE4) -The purpose of this repository is to share our quick multi-environment setup for ExpressionEngine 2. We use this on every EE project to quickly and easily get support for multiple servers setup. This enables us to deploy any of our sites to any server with minimal changes or updates to any code or settings. +The purpose of this repository is to share our quick multi-environment setup for ExpressionEngine 4. We use this on every EE project to quickly and easily get support for multiple servers setup. This enables us to deploy any of our sites to any server with minimal changes or updates to any code or settings. h2. Introduction @@ -35,13 +35,16 @@ h3. Environment Declaration This file is the starting point of your environment setup. Based on the @HTTP_HOST@ variable in PHP we define the environment (this may change if you're using a load balance environment or EE's MSM module). This is handled in the @config.env.php@ file. +You should *never* use @HTTP_HOST@ to define the actual domain of your site. Someone could use a header to change the value of @HTTP_HOST@ which would cause *all* of your URLs to go to a domain of their choosing. For more details, take a look at "this article":http://carlos.bueno.org/2008/06/host-header-injection.html. + We approach the environment from the top down. We define all environments based on the domain and then set our default to "local" which allows our local developers to use whatever domain they choose (eg: mysite.dev, mysite.local, etc). -Three constants are defined in our environment declaration file. They are: +Four constants are defined in our environment declaration file. They are: * @ENV@ * @ENV_FULL@ * @ENV_DEBUG@ +* @ENV_DOMAIN@ *@ENV@* @@ -55,18 +58,15 @@ This is the full name of your environment. There are no requirements on this val This is our boolean debug flag used frequently in our master config file. It allows us to keep debug settings "on" in specific environments. You can see how this is used in the master config file. +*@ENV_DOMAIN@* + +This is the domain of your environment. It must contain the domain (e.g. www.example.com or staging.example.com) for your environment. + h3. Master Config file Our @config.master.php@ file contains the bulk of the data for our setup. These are default configuration settings for our EE projects. Here we break up config settings into logical groups and add/remove as needed per project. In plain English, this is what the @config.master.php@ document does/says: -
If EE is looking for database credentials
-	Load our environment-specific file (eg: config.prod.php)
-	Define our DB cache directory
-	Merge our expressionengine/config/database.php array with our environment-specific db array
-	Unset our environment-specific array now that it's been used as needed
-End if
-
-If EE is looking for config array values
+
If EE is looking for config array values
 	Define our base paths (as inspired by Matt Weinberg)
 	Define our template config settings
 	Define our Debug settings
@@ -81,11 +81,7 @@ End if
*Override Options* -You can find a list of available configuration override options here on the EE Wiki page "EE 2 Config Overrides":http://expressionengine.com/wiki/EE_2_Config_Overrides. You can alternatively find individual setting array keys by "inspecting" elements within EE's Control Panel and taking note of the input names. Third party developers may also include config override support in their add-ons. - -*Templates Settings* - -You can now change the location of your templates directory. Find @$env_config['tmpl_file_basepath']@ around line @132@ in the @config.master.php@ and change the value as needed. +You can find a list of available configuration override options here on the EE Wiki page "EE 4 Config Overrides":https://docs.expressionengine.com/latest/general/system_configuration_overrides.html. You can alternatively find individual setting array keys by "inspecting" elements within EE's Control Panel and taking note of the input names. Third party developers may also include config override support in their add-ons. *Global Variables* @@ -102,10 +98,17 @@ There are three possible arrays to use here. They are @$env_db@, @env_config@ an This is just for your database credentials for the environment. *What makes this convenient is that we ignore our @config.local.php@ file from Git.* That way each local developer has their own config overrides that won't affect the main repository. -
$env_db['hostname'] = '';
-$env_db['username'] = '';
-$env_db['password'] = '';
-$env_db['database'] = '';
+
$config['database'] = array (
+	'expressionengine' => array (
+		'hostname' => 'localhost',
+		'username' => '',
+		'password' => '',
+		'database' => '',
+		'dbdriver' => 'mysqli',
+		'dbprefix' => 'exp_',
+		'pconnect' => FALSE
+	),
+);
*@$env_config@* @@ -125,24 +128,20 @@ This gives you variables like @{global:google_analytics}@ in your EE templates. h2. Setup * First, make sure you're working in an pre-existing EE install (even if you just installed EE a few minutes ago). You can't setup this config until after EE is installed. -* Copy the @/config@ directory to the same directory level as your @system@ directory (we recommend "above web root":http://expressionengine.com/user_guide/installation/best_practices.html#moving-the-system-directory-above-webroot) +* Copy the @/config@ directory to the same directory level as your @system@ directory (we recommend "above web root":https://docs.expressionengine.com/latest/installation/best_practices.html) * Modify @config.env.php@ to reflect your environments and domains. You can remove and add environments as needed * Update each @config.{env}.php@ file with each environment's database credentials as needed * Create config overrides and global variables for each environment as needed -* Add the following code to the bottom of @system/expressionengine/config/config.php@ (be sure not to delete other config settings already in this file): +* Add the following code to the bottom of @system/user/config/config.php@ (be sure not to delete other config settings already in this file):
/**
  * Require the Focus Lab, LLC Master Config file
  */
 require $_SERVER['DOCUMENT_ROOT'] . '/../config/config.master.php';
 
-
 /* End of file config.php */
 /* Location: ./system/expressionengine/config/config.php */
-* Replace the contents of your @system/expressionengine/config/database.php@ file with the contents in of the same file in this repository - - h3. Above webroot vs within webroot The instructions above are for setting up the config *above* webroot (your "public_html", "htdocs", etc directory). This is recommended for security. However, if you're unable to do this due to hosting restraints you can find the necessary changes to support this "on StackExchange.":http://expressionengine.stackexchange.com/questions/13731/focus-labs-ee-master-config-under-webroot diff --git a/system/expressionengine/config/database.php b/system/expressionengine/config/database.php deleted file mode 100644 index cb58ed2..0000000 --- a/system/expressionengine/config/database.php +++ /dev/null @@ -1,19 +0,0 @@ -