Host multiple blogs with default WordPress?

Internet

WordPress icon.

Vinícius Lira over in this comments thread has proposed a ridiculously elegant solution to using a default WordPress installation to host multiple blogs on different databases. If it works, it's genius.

  1. Create a subdomain that points to your WordPress installation, such as http://newblog.site.com/

  2. Create a new database, such as newblog

  3. Edit the wp-config.php file and replace:

    define('DB_NAME', 'wordpress');

    with:

    if($_SERVER['HTTP_HOST'] == "site.com" or
    $_SERVER['HTTP_HOST'] == "www.site.com") {
    	define('DB_NAME', "mysitedatabase");
    }
    elseif ($_SERVER['HTTP_HOST'] == "newblog.site.com") {
    	define('DB_NAME', "newblog");
    }
    

Haven't tested it myself yet, but it seems too simple. It shouldn't work. If it does, it'd be schweet.

Author bio and support

Me!

Ruben Schade is a technical writer and IaaS engineer in Sydney, Australia who refers to himself in the third person in bios. Wait, not BIOS… my brain should be EFI by now.

The site is powered by Hugo, FreeBSD, and OpenZFS on OrionVM, everyone’s favourite cloud infrastructure provider.

If you found this post helpful or entertaining, you can shout me a coffee or buy some silly merch. Thanks!