Multisite Setup sub_directory

Hi,

I’m trying to set up a site in ./user/site/2ndSite following the instruction here https://learn.getgrav.org/advanced/multisite-setup

But it’s not working out for me. I’m guessing the procedure is something like this. But… is it?

  1. create setup.php with sub_dir content in grav root dir
  2. create directory mkdir -p ./user/site/2ndSite/themes
  3. copy the contents of learn2-git-sync theme zip file into the themes file
  4. copy ./user/themes/animatter to ./user/site/2ndSite/themes
  5. create directories pages, accounts, data, config in ./user/site/2ndSite/
  6. cp -a ./user/plugins ./user/site/2ndSite/

I’ve tried all sort of combinations of files and directories, but no success. :frowning:

Can someone please explain the way to do it?

Thanks!

in your list , can’t see reference to setup.php

Yes, that’s the first step I did. And grav is reading it.

paste your setup.php

<?php
/**
 * Multisite setup for sub-directories or path based
 * URLs for subsites.
 *
 * DO NOT EDIT UNLESS YOU KNOW WHAT YOU ARE DOING!
 */

use Grav\Common\Filesystem\Folder;

// Get relative path from Grav root.
$path = isset($_SERVER['PATH_INFO'])
   ? $_SERVER['PATH_INFO']
   : Folder::getRelativePath($_SERVER['REQUEST_URI'], ROOT_DIR);

// Extract name of subsite from path
$name = Folder::shift($path);
$folder = "sites/{$name}";
$prefix = "/{$name}";

if (!$name || !is_dir(ROOT_DIR . "user/{$folder}")) {
    return [];
}

// Prefix all pages with the name of the subsite
$container['pages']->base($prefix);

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

your directory /user/site/2ndSite/themes and in your setup.php there is folder = "sites/{$name}";

site / sites

Sorry, typo, my directory is ‘sites’

The instructions are vague.

If you choose sub-directories or path based URLs for subsites, then the only thing you need is to create a directory for each subsite in the user/sites directory containing at least the required folders config, pages, plugins and themes.

What contents should these folders have? How do required plugins get installed? How does the grav-admin fit in?

Test this setup.php

   <?php
    /**
     * Multisite setup for sub-directories or path based
     * URLs for subsites.
     *
     * DO NOT EDIT UNLESS YOU KNOW WHAT YOU ARE DOING!
     */

    use Grav\Common\Filesystem\Folder;

    // Get relative path from Grav root.
    $path = isset($_SERVER['PATH_INFO']) 
        ? $_SERVER['PATH_INFO'] 
        : Folder::getRelativePath($_SERVER['REQUEST_URI'], dirname($_SERVER['SCRIPT_NAME']));
    $path = preg_replace('|[?#].*$|', '', $path);

    // Extract name of subsite from path
    $name = Folder::shift($path);
    $folder = "sites/{$name}";
    $prefix = "/{$name}";

    if (!$name || !is_dir(ROOT_DIR . "user/{$folder}")) {
        return [];
    }

    // Prefix all pages with the name of the subsite
    $container['pages']->base($prefix);

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

After loggin in to learn2/admin, before I could not activate the learn2 theme. With the new setup I get: Fetch failed

{"status":"success","payload":{"resources":{"total":0,"plugins":[],"themes":[]},"grav":{"isUpdatable":false,"assets":{"grav-admin":{"name":"grav-admin-v1.3.4.zip","type":"application\/octet-stream","size":9069943,"download":"https:\/\/getgrav.org\/download\/core\/grav-admin\/1.3.4"},"grav-update":{"name":"grav-update-v1.3.4.zip","typ....

this is my structure
-user
— sites

---- siteA
----- Pages
----- Config
----- Themes
------ Mytheme
---- siteB
----- Pages
----- Config
----- Themes
------ Mytheme

<?php
/**
 * Multisite setup for sub-directories or path based
 * URLs for subsites.
 *
 * DO NOT EDIT UNLESS YOU KNOW WHAT YOU ARE DOING!
 */

use Grav\Common\Filesystem\Folder;

// Get relative path from Grav root.
$path = isset($_SERVER['PATH_INFO'])
   ? $_SERVER['PATH_INFO']
   : Folder::getRelativePath($_SERVER['REQUEST_URI'], ROOT_DIR);

// Extract name of subsite from path
$name = Folder::shift($path);
$folder = "sites/{$name}";
$prefix = "/{$name}";

if (!$name || !is_dir(ROOT_DIR . "user/{$folder}")) {
    return [];
}

// Prefix all pages with the name of the subsite
$container['pages']->base($prefix);

$themes = ["user/themes"];
if (is_dir(__DIR__ . "/user/sites/{$folder}/themes")) {
  array_unshift($themes, "user/sites/{$folder}/themes");
}

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

            'themes' => [
                'type' => 'ReadOnlyStream',
                'prefixes' => [
                    '' => $themes,
                ]
            ],

        ]
    ]
];
2 Likes

Thanks :slight_smile:
So plugins and admin are managed from the base installation?

in my case yes, but you can add plugins folder in each subsites, so each subsite can have his own plugins

Got it working.
I made two different grav (with admin included) installations. Main-web and sub-web. On main-web I installed a blog theme and on sub-web i installed knowledge-base theme. Then copied accounts, data, pages, config, themes, plugins from sub-web into the user/sites/docs folder in main-web.

Now I have a blog working at localhost:8000 and localhost:8000/admin
And a knowledge base at localhost:8000/docs and localhost:8000/docs/admin

Thanks! :slight_smile:

@tuttle glad to hear it :slight_smile:

You can then mark this as solved :wink:

Hey guys, I’m reading through this thread and this is exactly what I want to do. Dumb question, do I need a “setup.php” and a “setup_subdomain.php” …or just the “setup.php” file with the sub domain code snippet in it?

1 Like

Hi,

Choose the one you need and rename it to setup.php

Good luck!

Hey Tuttle, thanks for the quick reply! I just tried that, but now I’m just not sure what to do next… Should I be seeing something in my admin? …kind of lost on what/where to go now?

Thanks in advance!

1 Like