Using the same wp-config.php file on local, dev, and on live server

Eystein
Eystein
Mar 17, 2015 · 1 min read

switch($_SERVER[‘SERVER_NAME’]){
/** Local dev */
case ‘mywebsite.dev’:
$db_name = ‘dev_mywebsite’;
$db_user = ‘username’;
$db_pass = ‘password’;
$db_host = ‘localhost’;
break;
/** Staging */
case ’staging.mywebsite.com’:
$db_name = ’staging_mywebsite’;
$db_user = ‘username’;
$db_pass = ‘password’;
$db_host = ‘mysql.mywebsite.com’;
break;
/** Production */
default:
$db_name = ‘prod_mywebsite’;
$db_user = ‘username’;
$db_pass = ‘password’;
$db_host = ‘mysql.mywebsite.com’;
}
define(‘DB_NAME’, $db_name);
define(‘DB_USER’, $db_user);
define(‘DB_PASSWORD’, $db_pass);
define(‘DB_HOST’, $db_host);
Eystein

Written by

Eystein

I'm a Norwegian sharing my time between the mountains and the web.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade