Profile image for Erica Strahon EricaStrahon
Convenient for using on development, staging, and live servers by using the switch statement. No need to edit multiple wp-config files, or ignore when using subversion. I also set debugging to 'true' when using on development server.
Language
PHP
Tags
svn switch wordpress wp-config
Favorited By
Profile image for Theoni Nuin Profile image for Mauro Artizzu Profile image for Aron P

One wp-config for multiple servers

1 <?php 2 /** 3 * The base configurations of the WordPress. 4 * 5 * This file has the following configurations: MySQL settings, Table Prefix, 6 * Secret Keys, WordPress Language, and ABSPATH. You can find more information 7 * by visiting {@link http://codex.wordpress.org/Editing_wp-config.php Editing 8 * wp-config.php} Codex page. You can get the MySQL settings from your web host. 9 * 10 * This file is used by the wp-config.php creation script during the 11 * installation. You don't have to use the web site, you can just copy this file 12 * to "wp-config.php" and fill in the values. 13 * 14 * @package WordPress 15 */ 16 17 // ** MySQL settings - You can get this info from your web host ** // 18 switch ($_SERVER['SERVER_NAME']) { 19 /** Development Server */ 20 case 'www.myserver.dev': 21 define('DB_NAME', 'database_name_here'); 22 define('DB_USER', 'username_here'); 23 define('DB_PASSWORD', 'password_here'); 24 define('DB_HOST', '127.0.0.1'); 25 define('DB_CHARSET', 'utf8'); 26 define('DB_COLLATE', ''); 27 define('WP_DEBUG', true); 28 break; 29 /** Staging Server */ 30 case 'stage.myserver.com': 31 define('DB_NAME', 'database_name_here'); 32 define('DB_USER', 'username_here'); 33 define('DB_PASSWORD', 'password_here'); 34 define('DB_HOST', 'localhost'); 35 define('DB_CHARSET', 'utf8'); 36 define('DB_COLLATE', ''); 37 define('WP_DEBUG', false); 38 break; 39 /** Production Server */ 40 case 'www.myserver.com': 41 define('DB_NAME', 'database_name_here'); 42 define('DB_USER', 'username_here'); 43 define('DB_PASSWORD', 'password_here'); 44 define('DB_HOST', 'localhost'); 45 define('DB_CHARSET', 'utf8'); 46 define('DB_COLLATE', ''); 47 define('WP_DEBUG', false); 48 break; 49 } 50 51 /**#@+ 52 * Authentication Unique Keys and Salts. 53 * 54 * Change these to different unique phrases! 55 * You can generate these using the {@link https://api.wordpress.org/secret-key/1.1/salt/ WordPress.org secret-key service} 56 * You can change these at any point in time to invalidate all existing cookies. This will force all users to have to log in again. 57 * 58 * @since 2.6.0 59 */ 60 define('AUTH_KEY', 'AUTH_KEY_HERE'); 61 define('SECURE_AUTH_KEY', 'SECURE_AUTH_KEY_HERE'); 62 define('LOGGED_IN_KEY', 'LOGGED_IN_KEY_HERE'); 63 define('NONCE_KEY', 'NONCE_KEY_HERE'); 64 define('AUTH_SALT', 'AUTH_SALT_HERE'); 65 define('SECURE_AUTH_SALT', 'SECURE_AUTH_SALT_HERE'); 66 define('LOGGED_IN_SALT', 'LOGGED_IN_SALT_HERE'); 67 define('NONCE_SALT', 'NONCE_SALT_HERE'); 68 69 /**#@-*/ 70 71 /** 72 * WordPress Database Table prefix. 73 * 74 * You can have multiple installations in one database if you give each a unique 75 * prefix. Only numbers, letters, and underscores please! 76 */ 77 $table_prefix = 'wp_'; 78 79 /** 80 * WordPress Localized Language, defaults to English. 81 * 82 * Change this to localize WordPress. A corresponding MO file for the chosen 83 * language must be installed to wp-content/languages. For example, install 84 * de.mo to wp-content/languages and set WPLANG to 'de' to enable German 85 * language support. 86 */ 87 define ('WPLANG', ''); 88 89 /* That's all, stop editing! Happy blogging. */ 90 91 /** Absolute path to the WordPress directory. */ 92 if ( !defined('ABSPATH') ) 93 define('ABSPATH', dirname(__FILE__) . '/'); 94 95 /** Sets up WordPress vars and included files. */ 96 require_once(ABSPATH . 'wp-settings.php');

Discussion

Problem with case statements. The urls stated will only allow Wordpress to work on that url only. Needs modifying so that it will allow Wordpress to work on both www and no www.

Comments