Multisite - global plugins

Hi, I’m just digging into multisite. Basic examples are working great.
But can someone help me with advanced configuration and streams?

I need specific config:
a) keep all plugins at one place globally for all sites
b) keep all my available themes at one place globally for all sites
c) force each site to have its own cache folder, media and assets etc…

If site will be able “extend” a) and b) and add its own custom plugin or theme locally
that will be great, but it is not necessary.

Thanks you.
Michal

Mulitsite is still very much in it’s infancy. We have done some basic testing but have not really tried to stretch it too far yet. Your asking for advice on things we haven’t even tried yet! Maybe someone else out that has done this? Could do with some help! :slight_smile:

Ok. Thanks.
Will be great to hear that multisite will be strong and flexible feature of Grav core in the ‘near’ future.
I’m just playing with symlinks. So I can put all of my sites out of the grav core, also I’m able link custom plugins, themes etc. So it is possible make “shared” parts with that. But symlinks are not possible to manage well and it is pretty dangerous solution. Otherwise it is working some how. The reason? I need one place which will be used to manage core, own core plugins, available themes etc.

FYI, I use symlinks extensively in my development environment. Grav actually natively supports them if you have a .grav/config file defined. So you can even install stuff via GPM, and it will just symlink it (assuming you have the plugin/theme cloned). More information in the Developer Docs

I did play with multisite little bit more.

a)
Redirecting cache is working fine

b) admin plugin is using absolute path theme_url, so it is not possible use it with multisite setup.

c) Themes can override streams, that mean theme can break your environment.

Problems plugin is not working with multisite. In case you move your folders under subdomain folder. it is throwing error. The solution is disable problem plugin, or keep empty folders like data, account, themes etc… at /user folder.

yah problems is not really required once you have your site up and running. It’s really intended for first time users.

Hey,
Here is setup.php multisite config with these requirements:
a) shared themes for all sites (user/themes)
b) shared plugins for all sites (user/plugins)
c) keep cache separate for each site (user/sites/yoursubdomainfolder/cache)

/**
 * Multisite setup for subsites accessible via sub-domains.
 */

use Grav\Common\Utils;

// Get subsite name from sub-domain
$environment = isset($_SERVER['HTTP_HOST'])
    ? $_SERVER['HTTP_HOST']
    : (isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : 'localhost');
// Remove port from HTTP_HOST generated $environment
$environment = strtolower(Utils::substrToString($environment, ':'));
$folder = "sites/{$environment}"; 

if ($environment === 'localhost' || !is_dir(ROOT_DIR . "user/{$folder}")) {
    return [];
}

return [
    'environment' => $environment,
    'streams' => [
        'schemes' => [
            'user' => [
                'type' => 'ReadOnlyStream',
                'prefixes' => [
                    '' => ["user/{$folder}"],
                ]
            ],
            'cache' => [
                'type' => 'ReadOnlyStream',
                'prefixes' => [
                    '' => ["user/{$folder}/cache"],
                ]
            ],
            'plugins' => [
                'type' => 'ReadOnlyStream',
                'prefixes' => [
                    '' => ["user/plugins"],
                ]
            ],
            'themes' => [
                'type' => 'ReadOnlyStream',
                'prefixes' => [
                    '' => ["user/themes"],
                ]
            ],
            'images' => [
                'type' => 'ReadOnlyStream',
                'prefixes' => [
                    '' => ["user/{$folder}/images"],
                ]
            ]
        ]
    ]
];

Important

  • You need disable Problems plugin.

Multisite config 2
a) each site has own plugins
b) each site has own templates
c) each site has own cache folder

/**
 * Multisite setup for subsites accessible via sub-domains.
 */

use Grav\Common\Utils;

// Get subsite name from sub-domain
$environment = isset($_SERVER['HTTP_HOST'])
    ? $_SERVER['HTTP_HOST']
    : (isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : 'localhost');
// Remove port from HTTP_HOST generated $environment
$environment = strtolower(Utils::substrToString($environment, ':'));
$folder = "sites/{$environment}";

if ($environment === 'localhost' || !is_dir(ROOT_DIR . "user/{$folder}")) {
    return [];
}

return [
    'environment' => $environment,
    'streams' => [
        'schemes' => [
            'user' => [
                'type' => 'ReadOnlyStream',
                'prefixes' => [
                    '' => ["user/{$folder}"],
                ]
            ],
            'cache' => [
                'type' => 'ReadOnlyStream',
                'prefixes' => [
                    '' => ["user/{$folder}/cache"],
                ]
            ],
            'images' => [
                'type' => 'ReadOnlyStream',
                'prefixes' => [
                    '' => ["user/{$folder}/images"],
                ]
            ]
        ]
    ]
];

Important

  • Disable Problems plugin
  • Double check template yaml file. There can be streams - schema override, which breaks your configuration form setup.php.
    I’m not sure why this can be changed from template but it is possible.
    So if you find lines like this in your theme (antimatter.yaml example) delete them.
streams:
  schemes:
    theme:
      type: ReadOnlyStream
      paths:
        - user/themes/antimatter

Double check if it has some side effects. But seems everything working ok.
Michal

Nice! If you could put this in the Multisite Docs will be very helpful for others too, and will make sure we don’t lose this in the forum.

I checked the Antimatter issue with Matias, those lines are actually not needed, so I’ll remove them from the theme and other themes that copied those lines from Antimatter.

It is not problem of antimatter only. Please make one grav template which will work as kitchensink. Will be maintained and will be able to used as reference.

Antimatter is the ‘default’ Grav theme and the one that we use for all our testing. We do plan on releasing a kitchen-sink type skeleton for testing however. We currently have a skeleton we use internally, but it’s just a jumble of random things and needs significant tidying up and restructuring.

I know this very well. :wink:

@mihot I mentioned Antimatter but I removed that from all the themes since every theme copied Antimatter basically.

@flaviocopes yes you are right :slight_smile: I’m also starting with antimatter as base.