How multisite works?

Can someone voluntarily introduce me to how multisite works and how it’s supposed to be implemented.

I read https://getkirby.com/docs/advanced/customized-folder-setup
But it assumes one understands it in advance.
I can copy/paste that, then what is supposed to happen, what should I expect?

Thanks.

I’ve never tried that, but if I understand it correctly, you basically have a single Kirby installation, only your /site, /content, thumbs/ and /assets/avatars folders contain subfolders for each domain, e.g.

/site/domain.one.com
/site/domain.two.com
/site/domain.three.com

etc.

You need to provide a site.php with the code as laid out in the example. Kirby then automatically fetches the right stuff for each domain.

I use this setup to run a hosted version of Shopkit for a few clients.

Essentially the root /content folder gets deleted, and instead I have

assets
kirby
panel
site
clients
    client-one
        content
        accounts
    client-two
        content
        accounts
    client-three
        content
        accounts

So that gives me common folders used by all three sites, so the core/assets/templates/blueprints/panel can all be updated at once.

With the setup above, every client can manage their own content, but all three sites are actually being powered by the same core/template/plugin files.

1 Like

Do you use multiple domains, or you are separating local content?

Thank you. The idea sounds useful to me.

I followed the docs example, but don’t know what to expect really.
I don’t know if I have the same idea of “multisite”.

Nothing happens after I create /site.php.
So I guess I don’t get the picture.

Ok, I briefly tested this locally with Mamp and got it to work:

  1. Use the example site.php and put it into the root of your kirby install. Change domains to fit your setup, I used fake domains called domain-1.com and domain-2.com

  2. Create subfolders with those domain names like I explained above, i.e.

/content/domain-1.com
/content/domain-2.com

/site/domain-1.com
/site/domain-2.com

/thumbs/domain-1.com
/thumbs/domain-2.com

/assets/avatars/domain-1.com
/assets/avatars/domain-2.com
  1. I used the starterkit as a basis, so I moved all the stuff from the original /site and /content folders into /content/domain-1.com and site/domain-2.com and then copied and pasted the stuff into the /content/domain-2.com and /site/domain-2.com

  2. In my /etc/hosts file I added the following lines:

127.0.0.1 domain-1.com
127.0.0.1 domain-2.com

In my httpd-vhosts.conf file I added the Virtual hosts (Mamp/conf/apache/extra):

<VirtualHost *:80>
    DocumentRoot "/Applications/Mamp/htdocs/multisite"
    ServerName domain-1.com
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot "/Applications/Mamp/htdocs/multisite"
    ServerName domain-2.com
</VirtualHost>

Now I can access the Kirby installation in my browser by calling domain-1.com/domain-2.com.

You would probably have to enable vhosts in your httpd.conf file.

If you use another setup, you have to adapt this to test it.

Make some changes to any of the installs to experience the difference.

Hope this helps.

Yep, three different domains. They’re not connected in any way other than using the same core files.

THAT is a significant piece of setup.
I would have never guessed that.
Let me try it and see what comes out of it.

First time trying this.
Sounds very interesting.

@heyallan: If you don’t need different templates etc. you can also use a setup as described by @samnabi. In that setup, only the content folder is different for the domains, all the rest (templates, snippets, configuration, thumbs etc.) is shared by the different domains.

Or, just add a templates/ folder under client-one, client-two, etc…

Since the folder locations are defined in site.php, you can really have any folder structure that makes sense to you.

@samnabi Yes, that’s right, but what I meant to say was that if you want to share templates across sites, you don’t need to have different template folders (no matter where you put them).

Thank you both :thumbsup:

How does your site.php looks like?
I’m interested in something like that.

// site.php

$kirby   = kirby();
$domain  = server::get('server_name');

// Invalid subdomain redirects to client-one.com
$clients = array_diff(scandir(__DIR__.'/shops'), array('..', '.','.DS_Store'));
if (!in_array($domain, $clients)) {
    $client = 'client-one.com';
} else {
    $client = $domain;
}

// custom roots
$kirby->roots->content = __DIR__ . DS . 'shops' . DS . $client . DS . 'content';
$kirby->roots->avatars = __DIR__ . DS . 'shops' . DS . $client . DS . 'avatars';
$kirby->roots->thumbs  = __DIR__ . DS . 'shops' . DS . $client . DS . 'thumbs';
$kirby->roots->accounts  = __DIR__ . DS . 'shops' . DS . $client . DS . 'accounts';

// custom urls
$kirby->urls->index    = url::scheme() . '://' . $client;
$kirby->urls->content  = $kirby->urls->index . DS . 'shops' . DS . $client . DS . 'content';
$kirby->urls->avatars  = $kirby->urls->index . DS . 'shops' . DS . $client . DS . 'avatars';
$kirby->urls->thumbs   = $kirby->urls->index . DS . 'shops' . DS . $client . DS . 'thumbs';

Very useful.
I think I’m getting the picture.

@texnixe Yes, it works as described.

I can make www.apples.com, and www.oranges.com, use same installation with custom folders (I’m on MAMP)

Except httpd-vhosts.conf, and httpd.conf, don’t have any visible effect.
I played with those, but nothing changes.

I read tutorials about vhosts and I think I’m doint it right.
But I’m worried about vhosts not working (?).

Do you mean, it works without setting the virtual hosts? Have you restarted Apache after making those changes?

I think it worked like this because /etc/hosts file takes both domains to 127.0.0.1, that’s where MAMP is running with a kirby installation. Then site.php handles both domains. Good.

I think vhosts settings didn’t take any effect because it assumes port :80, and I had MAMP set to default :8888, I made them match and it worked. There’s tricky configurations everywhere.

In my case, I’m interested in having same kirby installation for both domains.
Then… if hosts, and site.php, makes it all work seamlessly, is vhosts really necessary?

I get the feel that vhosts is used in other kind of websites where no site.php exist, or where domains will contain separate contents.

I’m new to this, I’m not sure if I’m getting it right.

In my experience, no, vhosts isn’t necessary if you want all domains to go to the same place.

Makes sense!
Thank you very much!