Lance O. Posted November 17, 2022 Share Posted November 17, 2022 I typically work with three hosting environments: local, stage (on external server), and live. PW currently supports config-dev.php and config.php. I'd love to see support for an additional config file such as: config-stage.php config-test.php config-review.phpconfig-local.phpconfig-localhost.php or something similar. It would make it much easier to manage three hosting environments, each with their own database. 1 Link to comment Share on other sites More sharing options...
gebeer Posted November 17, 2022 Share Posted November 17, 2022 There is no built-in way ATM. But you can find some nice implementations here: Link to comment Share on other sites More sharing options...
Laikmosh Posted March 30, 2023 Share Posted March 30, 2023 On 11/17/2022 at 12:08 AM, Lance O. said: I typically work with three hosting environments: local, stage (on external server), and live. PW currently supports config-dev.php and config.php. I'd love to see support for an additional config file such as: config-stage.php config-test.php config-review.phpconfig-local.phpconfig-localhost.php or something similar. It would make it much easier to manage three hosting environments, each with their own database. Im currently using this setup to manage this exact case you mention, my folder structure is looking like this for all my environments: site ├── config.php └── config-dev.php My config.php has the usual stuff and a constant definition to detect my current environment like this: <?php # All the usual processwire configurations # Have my database setup with env vars: $config->dbHost = $_ENV['dbHost']; $config->dbName = $_ENV['dbName']; $config->dbUser = $_ENV['dbUser']; $config->dbPass = $_ENV['dbPass']; if ($_ENV['dbHostReader']) { $config->dbReader = [ 'host' => $_ENV['dbHostReader'] ]; } $config->dbPort = '3306'; /*------------------------------------*\ Detect environment \*------------------------------------*/ switch ($_SERVER['HTTP_HOST']) { case 'www.site.com': define('ENV', 'PRODUCTION'); break; case 'staging.site.com': define('ENV', 'STAGING'); break; default: define('ENV', 'LOCAL'); break; } Since config-dev.php is present on all my environments, it will prevent config.php from running, so I manually call it and then override the settings I need like this: # I call the normal config.php so that the usual stuff is loaded as always require_once 'config.php'; # In case env vars failed if (!$config->dbHost) die('Missing env vars'); if ('LOCAL' === ENV) { $config->moduleInstall('download', true); // tracy config for dev development $config->tracy = [ 'outputMode' => 'development', 'guestForceDevelopmentLocal' => true, 'forceIsLocal' => true, // use this only on local dev!!!! ]; /** * Disable all HTTPS requirements? */ $config->noHTTPS = true; } if ('STAGING' === ENV) { # Staging settings... } This way I can use the exact same codebase on all my environments, hope this helps 2 Link to comment Share on other sites More sharing options...
Lance O. Posted March 31, 2023 Author Share Posted March 31, 2023 @Laikmosh This is great, thank you so much! Link to comment Share on other sites More sharing options...
bernhard Posted March 31, 2023 Share Posted March 31, 2023 I've just added a small PR that makes PW load config-local.php additionally to config.php if the file exists: https://github.com/processwire/processwire/pull/267 1 Link to comment Share on other sites More sharing options...
Lance O. Posted March 31, 2023 Author Share Posted March 31, 2023 @bernhard Brilliant, thank you! 1 Link to comment Share on other sites More sharing options...
Arklogic Posted May 1 Share Posted May 1 Hmm, why is this not part already of 3.0.229? 1 Link to comment Share on other sites More sharing options...
cwsoft Posted May 1 Share Posted May 1 @ArklogicFor actual PW versions, just put your live config settings into config.php and your local development settings into config-dev.php and don‘t upload the dev config to your live site. This works quite well for small sites/teams. In config-dev.php you could use plain PHP to read from .env or add switches to reflect different stages based on a variable, flag etc. 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now