Support » Requests and Feedback » 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).




     /** 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?

    • This topic was modified 1 year, 2 months ago by  xdega.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Not everyone uses GIT and/or Composer. 🙂

    Even if you are using any type of source control system, the wp-config.php file shoudln’t be part of what’s checked in anyway. That should always be local, and only local, therefor ignored by the versining system for any updates or commits.

    You’ve also got to keep in mind just how many sites out there are still running on out-dated server software (mainly PHP < 5.6) so there’s a very big chance that the namespacing that you’re using will break things for a whole lot of people.

    Using ENV vars is great – at my company we’re using Bedrock and ENV is one of it’s features. Also I think it’s a very nice implementation of this.

    On the other hand I don’t think putting ENV variables into core is a good thing – It’s only useful for developers. If you would like to implement it – create a plugin.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Implement Env Variables for wp-config?’ is closed to new replies.