More than 1 Site > Developing locally > A Local Multisite Use Case? Gotchas? Setup?


#1

EDITED: To refine question following further researcha and lack of response.

I am using grav on two sites now (family blog and my site), and possibly a friend’s business site soon too.

I develop locally on my Windows computer. As I don’t have SSH or Git access with my webhost (nor will I with my friend’s separate webhost), I do my edits locally and then manually upload the user/ folder to my webhost with Mozilla (sigh).

I currently use separate installs of Grav for each site, but this means I have to jump around between them to get to their respective user/ folders, then fire up their php servers and also fire up sass.

To speed things up, I’d ideally like to:

  1. Go to one place and start up (server and sass scripts) and use my editor to the relevant site’s user folder and start editing.
  2. Have access to each site’s admin as I want to extend that and so want to see if it works.
  3. When done, I can then simply grab the relevant site’s user/ folder and upload it with Mozilla to the relevant webhost.

This seems to me like a good use case for a local multisite-setup.

Questions:

  1. Is this a good use case for Multisite?
    [If so]
  2. Any gotchas/considerations? [ e.g. memory killer / slow <= I’m on an 6 year old laptop but this is only for local dev ]
  3. How to set it up setup?
    3.1 Do I do any edits to the subdirectory script below (happy with subfolders off localhost 8000)?
    3.2 Or do I leave this as is, and just rename the sites’s user/ folders like user_site1/, user_site2/?
    3.3 Or do I simply drop the script in root, without renaming user/ folders, and it will create paths

local-grav-multisite-root/setup_subdirectory.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}"],
               ]
            ]
        ]
    ]
];

Any example scripts for localhost to differentiate between the site’s user/ folders (`e?

Hope this makes sense.

Thanks


#2

I have no answer to this (my guess is that you’ll have to come up with your own custom solution, I’ve never seen a plugin or anything for the job), but I would also like to be able to do that! Some sort of multisite setup, that would be fabulous. subscribing


#3

@Netzhexe I’ve amended my questions.
But I’ve found Grav does have multisite - referred in docs too.
I am about to try a setup, but you can have a look at this answer for a starter.
Hope it helps.


#4

I’ve been running 5 grav sites on my ISP account, and did this from the beginning. Though I just run them as subdomains to the main account, which for many ISPs that is an additional cost, but very small. In my case I set that up through cPanel and direct them to different folders, so they are running in parallel. Could there be benefits to sharing the grav system, maybe. That is a question for a more experienced user. In my case there are 3 different themes running, and I am not sure whether that could be done if I were to try to merge the sites.