Skip to content
Grav 2.0 is officially stable. Read the announcement →

Community guidelines

Please keep discussions civil and on-topic. Repeated violations may lead to a temporary ban.

Installation & Hosting

Multisite Setup sub_directory

Started by Chris 9 years ago · 17 replies · 4114 views
9 years ago

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

Can someone please explain the way to do it?

Thanks!

last edited 10/02/17 by Chris
9 years ago

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

9 years ago

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

9 years ago

paste your setup.php

9 years ago

<?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}"],
    ]
    ]
    ]
    ]
    ];

9 years ago

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

site / sites

9 years ago

Sorry, typo, my directory is 'sites'

9 years ago

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?

9 years ago

Test this setup.php

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}"],
                   ]
                ]
            ]
        ]
    ];
9 years ago

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

9 years ago

this is my structure
-user
--- sites

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

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);

$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
9 years ago

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

9 years ago

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

9 years ago

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! :)

9 years ago

@tuttle:
Got it working.

@tuttle glad to hear it 🙂

You can then mark this as solved 😉

9 years ago

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
9 years ago

Hi,

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

Good luck!

9 years ago

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

Suggested topics

Topic Participants Replies Views Activity
Installation & Hosting · by antoinep, 11 hours ago
5 59 5 hours ago
Installation & Hosting · by Jürgen Dietrich, 7 months ago
0 60 7 months ago
Installation & Hosting · by rappluk, 8 months ago
0 61 8 months ago
Installation & Hosting · by N, 12 months ago
3 71 12 months ago
Installation & Hosting · by Youle, 1 year ago
1 60 1 year ago