Using Kirby for multiple sites
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.
Custom folder and URL setup
A multi-site setup extends Kirby’s possibility to define your custom folder setup and custom URL setup.
Setting up your multisite
To run multiple sites on a single Kirby installation, modify the index.php
at the root of your installation:
<?php
require 'kirby/bootstrap.php';
$sites = [
'my-site.com' => 'my-site.com',
'my-shop.com' => 'my-shop.com',
];
$host = Url::host();
$root = $sites[$host];
$url = 'http://' . $host;
$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',
],
]);
echo $kirby->render();
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->render()
:
$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',
],
]);
In the filesystem
- kirby
my-site.com
- content
- media
- site
- assets
my-shop.com
- content
- media
- site
- assets
- index.php
Licenses for your multi-site
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.