Implement Env Variables for wp-config?
-
Hi. I just wanted to float the idea of modernizing the default wp-config, by implementing support for environment variables?
I currently have this implementation working, by pulling in .ENV support via a PHP Composer package. I am populating my wp-config file with environment variables (see below).
.env
DB_NAME=... DB_USER=... DB_PASSWORD=... DB_HOST=... TABLE_PREFIX=...
wp-config.php
/** Load .ENV Support Library **/ require_once(__DIR__ . '/vendor/autoload.php'); (new \Dotenv\Dotenv(__DIR__.'/'))->load(); ... /** MySQL database username */ define('DB_USER', getenv('DB_USER')); /** MySQL database password */ define('DB_PASSWORD', getenv('DB_PASSWORD')); /** MySQL hostname */ define('DB_HOST', getenv('DB_HOST')); ...
This allows much more flexibility, especially with a modern Web Development workflow. In fact, this is essential if you want to have a smooth Git-based workflow, with many developers working in their own local environments, and staging/production environments.
I would be happy to work on this and submit a pull request to make this a thing, but want to first ask if it is even in the realm of possibility that such a request be accepted into the WordPress codebase.
Thoughts? Comments?
- The topic ‘Implement Env Variables for wp-config?’ is closed to new replies.