ClassicPress PetitionsClassicPress Petitions
This is a read-only archive. Post or comment on the live version of this page on our forums.

Use one configuration file per environment

September 7, 2018 · 15:12 · Alan
Description

Like Bedrock does.
A common configuration file using environment variables or using dotenv allowing to define db passwords and salts.

Special configuration files for each environment :

  • development
  • staging
  • production
Voters
+25 more
Tags
Request: Add feature
Discussion
Adam Alicki

This would go a long way in developing locally vs. production (for those of us who have to deal with on-server files).

James Nylen

There are a number of better ways to solve this than multiple config files (lots of duplication). My favorite is https://github.com/vlucas/phpdotenv.

The way it works is you create a .env file for each environment, then in your wp-config.php file, you set the defines up like this:

define( 'DB_NAME', getenv( 'DB_NAME' ) );

I would be fine with us making an official recommendation here, or making a setup like this easier.

James Nylen

.

Alan

Exactly, but both goes hand in hand. You need .env to avoid storing db access in your project codebase, but multiple file per environment are useful because it can sometimes be annoying to add a lot of .env vars that are not that sensitive.

The simpler example are the debug display options that you may want set per environment and then forget.

Mike Schinkel

Effectively though, isn't this petition not so much "one configuration file per environment" but instead "Solve the problems associated with dev/test/stage/prod?"

Daniel Hendricks

Semi-related, at minimum: Define WP_ENV constant by default (after wp-config.php loaded, ofc)...
<code><pre>if( !defined( 'WP_ENV' ) ) define( 'WP_ENV', 'production' );</pre></code>