Setup multisite - only the content is different

I’m trying to setup a multisite where 2 websites are 100% identical except the content. So only the content is uniek and should be managed separate in their own panel.

I’ve looked at several posts here on the forum and of course the cookbook: https://getkirby.com/docs/cookbook/setup/multisite#setting-up-your-multisite

To be honest, I have a hard time understanding the code in the cookbook about the multisite. Can anybody point me in the right direction how I should configure this?

If it’s only about the content folder, then all you have to do is set content to the folder where your content is store in index.php

index.php

<?php
require 'kirby/bootstrap.php';

// in this array, the key refers to the domain, the value refers to the folder name, this can be different from the domain name. Inside those folders you would put the content and the media folders.
$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__,
    'content' => $root . '/content',
    'media'   => $root . '/media',
  ],
 'urls' => [
    'media'  => $url . '/' . $root . '/media',
  ],
]);

echo $kirby->render();

Ok, thank you.

Just to be sure, the index.php and all other folders I put in the root, let say www.mysite.com. The content and media folder I put in www.mysite.com/site1 and www.mysite.com/site2.

And what information do I put at $sites?

As I commented above, the array keys in the $sites array are your domain names, the values are the folder names where your domain-specific stuff is stored.

Ok, then it should be like this:

$sites = [
β€˜www.mysite.com/site1’ => β€˜site1’,
β€˜www.mysite.com/site2’ => β€˜site2’,
];

I’m sorry but I don’t understand what this does. The url and the folder are the same thing…

Just to be sure, the index.php and all other folders I put in the root, let say www.mysite.com. The content and media folder I put in www.mysite.com/site1 and www.mysite.com/site2.

The root folder is retrieved from the $sites array, depending on which domain is called. Not sure if this works with subfolders. Check what dumping Url::Host() returns for each domain

Ok, thank you.

But how does this work!? Because the index.php is in the root folder (www.mysite.com) but in the browser you navigate to www.mysite.com/site1

As I said, I don’t know if this works with subfolders instead of (sub)domains, have never tried that. This setup usually assumes that you use domain names that all point to the same root.

Why do you use subfolders if this concerns different website?

Maybe the approach which I proposed in this recipe is easier for you to accomplish. It requires that you set up 2 virtual hosts, each will serve one of your sites. In addition, you need to have access to your file system because you have to replace folders with symbolic links. If this does not fit your situation, you can skip the remaining part of this answer.

Once you have setup your file system and virtual hosts as it is proposed in the mentioned recipe, it is easy to extend it to the site and assets folders. You just need to replace them with the according symbolic links.

In the following example file structure I did this and moved the kirby, site and assets folder to a folder kirby-shared outside of the virtual hosts root folders, which are kirby-site1/htdocs and kirby-site2/htdocs. Then I replaced these folders with symbolic links to the shared folder:

kirby-shared/
β”œβ”€β”€ assets
β”œβ”€β”€ kirby
└── site
kirby-site1/
└── htdocs
    β”œβ”€β”€ assets -> ../../kirby-shared/assets
    β”œβ”€β”€ content
    β”‚   β”œβ”€β”€ 1_photography
    β”‚   β”œβ”€β”€ 2_notes
    β”‚   β”œβ”€β”€ 3_about
    β”‚   β”œβ”€β”€ error
    β”‚   β”œβ”€β”€ home
    β”‚   └── sandbox
    β”œβ”€β”€ kirby -> ../../kirby-shared/kirby
    β”œβ”€β”€ media
    β”‚   β”œβ”€β”€ pages
    β”‚   └── panel
    └── site -> ../../kirby-shared/site
kirby-site2/
└── htdocs
    β”œβ”€β”€ assets -> ../../kirby-shared/assets
    β”œβ”€β”€ content
    β”‚   β”œβ”€β”€ 1_photography
    β”‚   β”œβ”€β”€ 2_notes
    β”‚   β”œβ”€β”€ 3_about
    β”‚   β”œβ”€β”€ error
    β”‚   β”œβ”€β”€ home
    β”‚   └── sandbox
    β”œβ”€β”€ kirby -> ../../kirby-shared/kirby
    β”œβ”€β”€ media
    β”‚   β”œβ”€β”€ pages
    β”‚   └── panel
    └── site -> ../../kirby-shared/site

This is a real working example, just created with the recent starterkit. If you like, I can give you access to it to test.

I don’t see the difference between using subfolders or a different domain. Setup would be te same, only the reference of the url is different.

The goal is to maintain the templates, snippets, blueprint and assets in 1 place.

Another possibility is that site1 has a regular setup, and site2 uses the templates, snippets, blueprint and assets from site1.

Thanks for sharing. Looks like a complex setup, but might be an option.

Oh this is exactly the setup I need. I’m pretty lost though. Could you provide me your Starterkit sample files?

There is nothing special with the starterkit files I use for this. Just set up the kirby-site1 and kirby-site2 folders with the same starterkit and then move the folders of one site outside the virtual hosts docroots and replace all moved folders with a symbolic link. For the second and maybe even more sites just delete the folders and replace them by symbolic links. Just follow the cookbook recipe, especially the change to index.php: https://getkirby.com/docs/cookbook/setup/multisite-variant#in-index-php

If you are still lost, please specify at which point something is not working for you.

Thanks, I was struggling with the Symbolic Links but now it’s working like a charm :slight_smile:

Since the site/config folder is shared between two sites, how can I add a second license?

Good question - never thought about this, since initially, my primary goal has been to share the kirby program folder and to ease updating/testing with different versions.

However, thinking more about it, it would be better to not share the whole site folder, but only certain subfolders. I think I would definitely leave the cache, config and session subfolders as real folders and only symlinking the others like blueprints, controllers etc. Depends largely on what you want to achieve. If you would like to share accounts between your sites, share the accounts folder, if not, leave them alone.