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