I’ve seen a few posts about managing multiple WordPress configuration files in dev / prod environments. (Such as this one.) Many of them seem a bit over-engineered, so why make it more complicated than it has to be? Here is probably the fastest way to setup different configuration files for development and production environments in WordPress:
- Copy wp-config.php twice, as wp-config.dev.php and wp-config.prod.php
- Create a new wp-config.php file, input the snippet below:
Snippet:
<?php /* Config loading based on environment variable */ if(getenv('WP_ENV') === 'dev') include 'wp-config.dev.php'; else include 'wp-config.prod.php';
- In your VirtualHost configuration, set the appropriate environmental variable.
Development
SetEnv WP_ENV dev
Production
SetEnv WP_ENV prod
- You’re done!
Awesome post!
I just started custom developing my own WordPress themes, this is super helpful. Bookmarked :)