Multiple blogs, one installation.
I have a number of blogs, one personal one for work, one for testing , development, one for training and one for demonstration and on occasion i have need for more. It became such a bind to keep all the installations and all the plugins on the installations current so i began to look for a solution.
I first tried out WordpressMU this is a multi-user version of WordPress which shares most of the same code and is really for larger organisations to manage multiple blogs. Since its not 100% WordPress this wouldn’t work that well for my demo and testing installations, but most of all it seems to need URL rewriting and I’m on a windows platform that i can’t install the necessary drivers on i had to find an alternative.
The simplest of solutions to the problem is to use WordPress and play around a little with the wp_config.PHP. wp_config contains everything WordPress needs to connect your blogs database.
A regular wp_confifg will look a little like this
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | <?php // ** MySQL settings ** // define('DB_NAME', 'putyourdbnamehere'); // The name of the database define('DB_USER', 'usernamehere'); // Your MySQL username define('DB_PASSWORD', 'yourpasswordhere'); // ...and password define('DB_HOST', 'localhost'); // 99% chance you won't need to change this value define('DB_CHARSET', 'utf8'); define('DB_COLLATE', ''); // You can have multiple installations in one database if you give each a unique prefix $table_prefix = 'wp_'; // Only numbers, letters, and underscores please! // Change this to localize WordPress. A corresponding MO file for the // chosen language must be installed to wp-content/languages. // For example, install de.mo to wp-content/languages and set WPLANG to 'de' // to enable German language support. define ('WPLANG', ''); /* That's all, stop editing! Happy blogging. */ define('ABSPATH', dirname(__FILE__).'/'); require_once(ABSPATH.'wp-settings.php'); ?> |
As you can see the standard wp_config with the $table_prefix, to allow you to use one database for multiply blogs, if you replace this with a PHP switch statement you can easily access these blogs from the same installation.
For example
1 2 3 4 5 6 7 8 9 | switch (strtolower($_SERVER["SERVER_NAME"])) { case "www.site1.com": $table_prefix = 'wp_site1_'; break; case "www.site2.com": $table_prefix = 'wp_test_'; break; } |
You are not limited to using the same database, you could move the definitions for the host and user details into the case statement, but its best to keep it simple.
I’ve been running my blogs like this for a few months now with no problems.
Giveita try see is it works for you.




















March 20th, 2008 at 7:20 pm
well done, man