Title: wp-config switch
Last modified: August 21, 2016

---

# wp-config switch

 *  Resolved [dwcouch](https://wordpress.org/support/users/dwcouch/)
 * (@dwcouch)
 * [12 years, 3 months ago](https://wordpress.org/support/topic/wp-config-switch/)
 * I recently thought I’d simplify the process of migrating updates to sites from
   my local to a staging and finally to a production server by adding a switch to
   the wp-config to switch DB’s and in some cases FTP settings. This works great
   when using FTP alone.
 * However I’ve discovered that Duplicator ignores my switch case’s and updates 
   every instance of DB_NAME, DB_USER, DB_PASSWORD, etc…
 * I’m considering just creating a wp-config.switch file and then just copying and
   pasting the contents each time I migrate. Not elegant but….
 * Would y’all consider some logic to NOT override the switch? Or perhaps there’s
   a setting I’m missing?
 *     ```
       // ** MySQL settings - You can get this info from your web host ** //
       switch($_SERVER['HTTP_HOST']) {
       	/* DEVELOPMENT */
           case 'dev.mysite.com':
       		/** The name of the database for WordPress */
       		define('DB_NAME', 'wpdev_mysite');
   
       		/** MySQL database username */
       		define('DB_USER', 'dev_username');
   
       		/** MySQL database password */
       		define('DB_PASSWORD', 'dev_password');
   
       		/** MySQL hostname */
       		define('DB_HOST', 'localhost');
           break;
           /* STAGING */
           case 'stage.mysite.com':
       		/** The name of the database for WordPress */
       		define('DB_NAME', 'wpstage_mysite');
   
       		/** MySQL database username */
       		define('DB_USER', 'stage_username');
   
       		/** MySQL database password */
       		define('DB_PASSWORD', 'stage_password');
   
       		/** MySQL hostname */
       		define('DB_HOST', 'localhost');
           break;
           /* PRODUCTION */
           case 'mysite.com':
       		/** The name of the database for WordPress */
       		define('DB_NAME', 'wpprod_mysite');
   
       		/** MySQL database username */
       		define('DB_USER', 'username');
   
       		/** MySQL database password */
       		define('DB_PASSWORD', 'password');
   
       		/** MySQL hostname */
       		define('DB_HOST', 'localhost');
           break;
           default:
           break;
       ```
   
 * [https://wordpress.org/plugins/duplicator/](https://wordpress.org/plugins/duplicator/)

Viewing 1 replies (of 1 total)

 *  [Cory Lamle](https://wordpress.org/support/users/corylamleorg/)
 * (@corylamleorg)
 * [12 years, 3 months ago](https://wordpress.org/support/topic/wp-config-switch/#post-4577189)
 * Hey dwcouch,
 * That probably won’t work… Trying to create a state engine that even knows about
   a case statement would be pretty difficult… I think a better option might be 
   to have an option where the the wp-config.php wasn’t even replaced and then you
   could manually update.
 * Another possible work around would be to just leave the switch vars that you 
   want the plugin to replace and the put the other two case statements into separate
   include files then call include_once, or if you don’t any then put them all in
   includes…
 * Example:
 *     ```
       /* DEV */
       case 'dev.mysite.com':
       	incluce_once('wp-config-dev.php');
       	break;
       /* STAGING */
       case 'stage.mysite.com':
       	incluce_once('wp-config-qa.php');
       	break;
       /* PRODUCTION */
       case 'mysite.com':
       	incluce_once('wp-config-prod.php');
       	break;
       ```
   
 * I have used similar code on other projects…
 * Cheers~

Viewing 1 replies (of 1 total)

The topic ‘wp-config switch’ is closed to new replies.

 * ![](https://ps.w.org/duplicator/assets/icon-256x256.png?rev=2906985)
 * [Duplicator - Backups & Migration Plugin - Cloud Backups, Scheduled Backups, & More](https://wordpress.org/plugins/duplicator/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/duplicator/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/duplicator/)
 * [Active Topics](https://wordpress.org/support/plugin/duplicator/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/duplicator/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/duplicator/reviews/)

## Tags

 * [development](https://wordpress.org/support/topic-tag/development/)
 * [wp-config](https://wordpress.org/support/topic-tag/wp-config/)

 * 1 reply
 * 2 participants
 * Last reply from: [Cory Lamle](https://wordpress.org/support/users/corylamleorg/)
 * Last activity: [12 years, 3 months ago](https://wordpress.org/support/topic/wp-config-switch/#post-4577189)
 * Status: resolved