Home › Forums › Other › How to resolve database syncing when deploying with Git? › Re: How to resolve database syncing when deploying with Git?
July 20, 2012 at 2:08 pm
#106480
Participant
If you simply need to change siteurl and home paths then this seems to be an elegant wp-config.php addition:
if ($_SERVER == 'localhost:7000') {
update_option('siteurl', 'http://localhost:7000' );
update_option('home', 'http://localhost:7000' );
} elseif (get_bloginfo('url') !== 'http://domain.com') {
update_option('siteurl', 'http://domain.com' );
update_option('home', 'http://domain.com' );
}
the above could be combined with the following to switch between different db credentials:
if ($_SERVER[‘HTTP_HOST’] == ‘domain.com’) {
define(‘DB_NAME’, ‘dbnamelive’);
define(‘DB_USER’, ‘loginlive’);
define(‘DB_PASSWORD’, ‘passlive’);
} elseif ($_SERVER[‘HTTP_HOST’] == ‘staging.domain.com’) {
define(‘DB_NAME’, ‘dbnamestaging’);
define(‘DB_USER’, ‘loginstaging’);
define(‘DB_PASSWORD’, ‘passstaging’);
} else { //Catch all assumes you’re using DEV
define(‘DB_NAME’, ‘dbnamelive’);
define(‘DB_USER’, ‘loginlive’);
define(‘DB_PASSWORD’, ‘passlive’);
}
If you also have ssh access to your server you could give a spin to this PHP CLI script to keep the dbs in sync:
http://leehblue.com/sync-local-and-remote-database