# How multisite works?

**URL:** <https://forum.getkirby.com/t/how-multisite-works/3597>\
**Category:** Questions\
**Tags:** v2\
**Created:** [March 15, 2016, 6:15pm UTC](https://forum.getkirby.com/t/how-multisite-works/3597 "2016-03-15T18:15:19Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![heyallan](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/heyallan/32/829_2.png) [@heyallan](https://forum.getkirby.com/u/heyallan)\
**Post date:** [March 15, 2016, 6:15pm UTC](https://forum.getkirby.com/t/how-multisite-works/3597/1 "2016-03-15T18:15:19Z")

</div>

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](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.

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [March 15, 2016, 6:31pm UTC](https://forum.getkirby.com/t/how-multisite-works/3597/2 "2016-03-15T18:31:22Z")

</div>

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.

```auto
/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.

---

<div class="post-metadata">

**Author:** ![samnabi](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/samnabi/32/5535_2.png) [@samnabi](https://forum.getkirby.com/u/samnabi)\
**Post date:** [March 15, 2016, 7:06pm UTC](https://forum.getkirby.com/t/how-multisite-works/3597/3 "2016-03-15T19:06:40Z")

</div>

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

```auto
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.

---

<div class="post-metadata">

**Author:** ![heyallan](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/heyallan/32/829_2.png) [@heyallan](https://forum.getkirby.com/u/heyallan)\
**Post date:** [March 15, 2016, 8:15pm UTC](https://forum.getkirby.com/t/how-multisite-works/3597/4 "2016-03-15T20:15:59Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![heyallan](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/heyallan/32/829_2.png) [@heyallan](https://forum.getkirby.com/u/heyallan)\
**Post date:** [March 15, 2016, 8:21pm UTC](https://forum.getkirby.com/t/how-multisite-works/3597/5 "2016-03-15T20:21:06Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [March 15, 2016, 8:58pm UTC](https://forum.getkirby.com/t/how-multisite-works/3597/6 "2016-03-15T20:58:40Z")

</div>

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](http://domain-1.com) and [domain-2.com](http://domain-2.com)

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

```nohighlight
/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:

```auto
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):

```auto
<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](http://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.

---

<div class="post-metadata">

**Author:** ![samnabi](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/samnabi/32/5535_2.png) [@samnabi](https://forum.getkirby.com/u/samnabi)\
**Post date:** [March 15, 2016, 9:15pm UTC](https://forum.getkirby.com/t/how-multisite-works/3597/7 "2016-03-15T21:15:58Z")

</div>

> [@heyallan](#):
>
> Do you use multiple domains, or you are separating local content?

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

---

<div class="post-metadata">

**Author:** ![heyallan](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/heyallan/32/829_2.png) [@heyallan](https://forum.getkirby.com/u/heyallan)\
**Post date:** [March 16, 2016, 12:05am UTC](https://forum.getkirby.com/t/how-multisite-works/3597/8 "2016-03-16T00:05:49Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [March 16, 2016, 8:02am UTC](https://forum.getkirby.com/t/how-multisite-works/3597/9 "2016-03-16T08:02:04Z")

</div>

@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.

---

<div class="post-metadata">

**Author:** ![samnabi](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/samnabi/32/5535_2.png) [@samnabi](https://forum.getkirby.com/u/samnabi)\
**Post date:** [March 16, 2016, 1:03pm UTC](https://forum.getkirby.com/t/how-multisite-works/3597/10 "2016-03-16T13:03:33Z")

</div>

> [@texnixe](#):
>
> If you don’t need different templates etc. you can also use a setup as described by @samnabi

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.

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [March 16, 2016, 5:03pm UTC](https://forum.getkirby.com/t/how-multisite-works/3597/11 "2016-03-16T17:03:27Z")

</div>

@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).

---

<div class="post-metadata">

**Author:** ![heyallan](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/heyallan/32/829_2.png) [@heyallan](https://forum.getkirby.com/u/heyallan)\
**Post date:** [March 16, 2016, 5:12pm UTC](https://forum.getkirby.com/t/how-multisite-works/3597/12 "2016-03-16T17:12:22Z")

</div>

Thank you both 👍

---

<div class="post-metadata">

**Author:** ![heyallan](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/heyallan/32/829_2.png) [@heyallan](https://forum.getkirby.com/u/heyallan)\
**Post date:** [March 17, 2016, 3:19pm UTC](https://forum.getkirby.com/t/how-multisite-works/3597/13 "2016-03-17T15:19:19Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![samnabi](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/samnabi/32/5535_2.png) [@samnabi](https://forum.getkirby.com/u/samnabi)\
**Post date:** [March 17, 2016, 3:53pm UTC](https://forum.getkirby.com/t/how-multisite-works/3597/14 "2016-03-17T15:53:03Z")

</div>

```auto
// 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';

```

---

<div class="post-metadata">

**Author:** ![heyallan](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/heyallan/32/829_2.png) [@heyallan](https://forum.getkirby.com/u/heyallan)\
**Post date:** [March 17, 2016, 7:24pm UTC](https://forum.getkirby.com/t/how-multisite-works/3597/15 "2016-03-17T19:24:36Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![heyallan](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/heyallan/32/829_2.png) [@heyallan](https://forum.getkirby.com/u/heyallan)\
**Post date:** [March 18, 2016, 1:05am UTC](https://forum.getkirby.com/t/how-multisite-works/3597/16 "2016-03-18T01:05:42Z")

</div>

@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 (?).

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [March 18, 2016, 7:32am UTC](https://forum.getkirby.com/t/how-multisite-works/3597/17 "2016-03-18T07:32:12Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![heyallan](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/heyallan/32/829_2.png) [@heyallan](https://forum.getkirby.com/u/heyallan)\
**Post date:** [March 18, 2016, 3:18pm UTC](https://forum.getkirby.com/t/how-multisite-works/3597/18 "2016-03-18T15:18:43Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![samnabi](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/samnabi/32/5535_2.png) [@samnabi](https://forum.getkirby.com/u/samnabi)\
**Post date:** [March 18, 2016, 3:21pm UTC](https://forum.getkirby.com/t/how-multisite-works/3597/19 "2016-03-18T15:21:26Z")

</div>

> [@heyallan](#):
>
> 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?

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

---

<div class="post-metadata">

**Author:** ![heyallan](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/heyallan/32/829_2.png) [@heyallan](https://forum.getkirby.com/u/heyallan)\
**Post date:** [March 18, 2016, 6:11pm UTC](https://forum.getkirby.com/t/how-multisite-works/3597/20 "2016-03-18T18:11:18Z")

</div>

Makes sense!  
Thank you very much!

[Next page](https://forum.getkirby.com/t/how-multisite-works/3597.md?page=2)
