Multisite setup.py issue

I am attempting to get multisite working, and am getting various errors - I’m sure its something small, but I can’t see to quite pin down what it is.

I have a site set up in grav/user/sites/www. To test it I access it via www.localhost, using Chrome.

The setup.py file contains the following:

<?php
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');

$environment = strtolower(Utils::substrToString($environment, ':'));
$subdir = current(explode('.', $environment));
$dir = "user/sites/{$subdir}";

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

return [
    'environment' => $environment,
    'streams' => [
        'schemes' => [
            'user' => [
                'type' => 'ReadOnlyStream',
                'prefixes' => [
                    '' => ["{$dir}"],
                ]
            ]
        ]
    ]
];

I have confirmed that $dir is correct when testing.

When I attempt to access the www subdomain, I get the “Issues Found” page with errors such as “grav/user/data does not exist” for the data, pages, plugins and themes subdirectories.

I tried explicitly specifying them by returning the streams, as follows:

return [
    'environment' => $environment,
    'streams' => [
        'schemes' => [
            'user' => [
                'type' => 'ReadOnlyStream',
                'prefixes' => [
                    '' => ["{$dir}"],
                ]
            ],
            'accounts' => [
                'type' => 'ReadOnlyStream',
                'prefixes' => [
                    '' => ["{$dir}/accounts"],
                ]
            ],
            'config' => [
                'type' => 'ReadOnlyStream',
                'prefixes' => [
                    '' => ["{$dir}/config"],
                ]
            ],
            'pages' => [
                'type' => 'ReadOnlyStream',
                'prefixes' => [
                    '' => ["{$dir}/pages"],
                ]
            ],
            'plugins' => [
                'type' => 'ReadOnlyStream',
                'prefixes' => [
                    '' => ["{$dir}/plugins"],
                ]
            ],
            'themes' => [
                'type' => 'ReadOnlyStream',
                'prefixes' => [
                    '' => ["{$dir}/themes"],
                ]
            ]
        ]
    ]
];

However, this throws an exception: implode(): Invalid arguments passed

Additional details about the exception thrown, exception: implode(): Invalid arguments passed:

grav\system\src\Grav\Common\Uri.php at line 331:

$valid_page_types = implode('|', $config->get('system.pages.types'));

I’m guessing the underlying cause is that it can’t find $config for some reason.

Looks like the user folder you’re pointing to does not exist. I suggest following the examples in the Multisite docs first, and then if you need something custom in your setup.php, edit one thing at a time.