WordPress multi sites are a great way to serve many sites but only maintain one core set of resources for each. Still, there are drawbacks like the need to selectively activate certain plugins or themes for network-wide use.
An alternate approach which I only use to manage a couple sites on my local machine allows me to have the benefits of only having one install of WordPress on my entire machine but be able to load multiple sites with it without even running WordPress as a multisite. I do this very simply: By routing requests from different subdomains to different “wp-config.php” files that load unique database settings for each site. Pretty simple.
If you want to try something like this, here are the steps:
- create a new folder in the root directory for wordpress and call it something like “/wp-configs/”
- Copy and paste in a few different wp-config.php files into this folder
- Make sure your hosts file is configured to allow you to load different subdomains on your local server like “site1.localhost.com” or “site2.localhost.com” so you’ll have a way to differentiate requests. Alternatively, you could create a conditional based on a string in a sub-directory but using sub-domains is probably best.
- Create the routing code in your main wp-config.php. Something like the following:
$host = $_SERVER['HTTP_HOST']; $subdomain = array_shift((explode('.', $host))); if ($subdomain == 'site2') { include('wp-config/local-single-site2.php'); } else { include('wp-config/local-single-site1.php'); }
You can either define constants for debugging in the routing wp-config to enable globally or in each individual for more control.
It works well! You now only have to update and maintain one set of plugins or themes and each site has a unique database. Of course, you could ALSO just store all of these databases in the same database but change the table prefix for each install.
Of course, this really only works if you’re running a few sites this way but isn’t advisable if you’re running a massive multisite with hundreds of blogs or sites.
If you have any thoughts or reasons why you think this would be stupid to run in production, let me know.