Set up WordPress Database Connection for Dev Server and Live Server

If you are developing wordpress sites then more than likely you will be setting up a local dev version using something like MAMP PRO and then staging the development on your live production server at your web host.

By far the most easiest way I have found to accomplish auto switching between dev connection and live connection is to do the following.

  1. make two copies of your wp-config.php
  2. rename one of them wp-config-live.php
  3. rename the other file wp-config-dev.php
  4. open the original wp-config.php file and delete everything and drop in the following code

All you have to do then is edit the dev server name in wp-config.php, then just update the test and live config files and you are done.

Job Done! Now you have two separate config files for each server you are running.

{code type=php}