Using Kirby for multiple sites
Run multiple sites from the same Kirby installation.
You can run multiple sites via the same Kirby setup. This can help you maintain your sites as you only need to keep a single setup updated.
To run multiple sites on a single Kirby installation, modify the
index.php at the root of your installation:
Let's walk through this step by step: First we load the
kirby/bootstrap.php script and define our sites in an array with the domain as the key and the file directory root as the value:
$sites = [ 'my-site.com' => 'my-site.com', 'my-shop.com' => 'my-shop.com', ];
Then we use the
Url::host() method to retrieve the domain requested by the visitor and select the matching root for this one:
$host = Url::host(); $root = $sites[$host]; $url = 'http://' . $host;
Finally, we use this information to create a
$kirby object with custom roots and a custom URLs and output
$kirby = new Kirby([ 'roots' => [ 'index' => __DIR__, 'site' => $root . '/site', 'content' => $root . '/content', 'media' => $root . '/media', 'assets' => $root . '/assets' ], 'urls' => [ 'media' => $url . '/' . $root . '/media', 'assets' => $url . '/' . $root . '/assets', ], ]);
Even when running multiple sites through the same setup and code, you need a license for each of these sites: A single license is valid for a single Kirby installation, running on a single domain. If you add additional installations (i.e. under additional subdomains or subfolders) you need to purchase licenses for each of those installations.