Wordpress configuration file for multiple servers

Wordpress configuration file

Wordpress' configuration file is the wp-config.php file that is located in the top most wordpress directory. In this configuration file we should include our database parameters and our home and siteurl location directives.

Following is an example of configuration file settings that I use

if (strpos($_SERVER['HTTP_HOST'], 'localhost') !== false) { //local define('DB_NAME', 'marcwattscomau'); define('DB_USER', 'root'); define('DB_PASSWORD', ''); define('DB_HOST', '10.1.1.4'); define('ABSPATH', $_SERVER['DOCUMENT_ROOT'] . '/websites/marcwatts.com.au/'); define('WP_SITEURL', 'http://' . $_SERVER['HTTP_HOST'] . '/websites/marcwatts.com.au'); define('WP_HOME', 'http://' . $_SERVER['HTTP_HOST'] . '/websites/marcwatts.com.au'); } else if ($_SERVER['HTTP_HOST'] == '10.1.1.4') { //dev define('DB_NAME', 'marcwattscomau'); define('DB_USER', 'root'); define('DB_PASSWORD', ''); define('DB_HOST', 'localhost'); define('ABSPATH', $_SERVER['DOCUMENT_ROOT'] . '/websites/marcwatts.com.au/'); define('WP_SITEURL', 'http://' . $_SERVER['HTTP_HOST'] . '/websites/marcwatts.com.au'); define('WP_HOME', 'http://' . $_SERVER['HTTP_HOST'] . '/websites/marcwatts.com.au'); } else if (strpos($_SERVER['HTTP_HOST'], 'staging.') !== false) { //staging define('DB_NAME', 'marcwattcomau'); define('DB_USER', 'user'); define('DB_PASSWORD', 'password'); define('DB_HOST', 'localhost'); $_SERVER['DOCUMENT_ROOT'] = '/home/marcwatt/public_html'; define('ABSPATH', $_SERVER['DOCUMENT_ROOT'] . '/staging/marcwatts.com.au/'); define('WP_SITEURL', 'http://' . $_SERVER['HTTP_HOST'] . '/marcwatts.com.au'); define('WP_HOME', 'http://' . $_SERVER['HTTP_HOST'] . '/marcwatts.com.au'); } else { //live define('DB_NAME', 'marcwattscomau'); define('DB_USER', 'user'); define('DB_PASSWORD', 'password'); define('DB_HOST', 'localhost'); define('ABSPATH', $_SERVER['DOCUMENT_ROOT'] . '/'); define('WP_SITEURL', 'http://' . $_SERVER['HTTP_HOST']); define('WP_HOME', 'http://' . $_SERVER['HTTP_HOST']); }

By setting your wordpress configuration file with the above settings you can transfer the site between servers without hassles and problems.