Jump to content
apeisa

Multisite

Recommended Posts

(Added by Soma)

Note that this module is deprecated.

The newer and more maintained version is found here:

https://github.com/somatonic/Multisite/

You can get the current dev version here https://github.com/somatonic/Multisite/tree/dev

(Original Post)

Just pushed simple multisite module to github: https://github.com/a...ultisite.module


What this module does?
It allows you to run multiple sites with different domains run from single install, using same database. While you can easily do "subsites" like www.domain.com/campaign/, this allows you to turn that into www.campaign.com. This is nice stuff, when you have multiple simple sites, that all belong to same organisation and same people maintain.

How to use it?
Just create page with name like www.campaigndomain.com under your homepage, then edit this module through modules menu and add same domain there. If your domain resolves to same place where your main domain, it should just work. Please notice that if you have editing rights, it allows you to browse the site from www.olddomain.com/www.campaigndomain.com/, but users with no editing rights are redirected to www.campaigndomain.com (this is because session cookie is otherwise lost).

Any problems?
Not any real problems, at least yet known. Of course think twice when deciding should the site have own install instead of this. There are few benefits, like getting data from other sites, one admin view for all sites etc... but it can easily get out of the hands: number of templates, fields etc.. It is harder to maintain for sure.

Isn't there multisite support in core?
Yes, kind of. It is very different from this. It allows you to run multiple pw-installations with shared core files (/wire/ folder). This is totally different: this is single pw-installation which has multiple sites running from different domains.



This is basically just a wrapper with one config field for this little snippet Ryan posted here: http://processwire.c...ndpost__p__5578 (so most of the credit goes to Mr. Cramer here). What it also does is that it manipulates $page->path / url properties to have right subdomain value.

  • Like 9

Share this post


Link to post
Share on other sites

Antti, this looks fantastic. I'm pointing another domain to processwire.com so that I can test this out.

One suggestion that I have is to change this:

// If subdomain is visible on url, we might wanna redirect
if(strpos($_GET['it'],$subdomain) !== false) {
   // We don't redirect if one has editing access (because user would need to login on new domain also)
   $page = $this->pages->get("/". $_GET['it']);
   if(!$page->editable()) {
       $_GET['it'] = str_replace("{$subdomain}/", "", $_GET['it']);
       $this->session->redirect('http://' . $subdomain . '/' . $_GET['it']);
   }
}

…to this (or something like it, as I've not actually tested, but hopefully the intention is there): :)

// saved $_GET['it'], since PW unsets it after using it
// note this is an unsanitized variable, so only look at it, don't use it
protected $it;

public function init() { 
   $this->subdomainsArray = explode("\n", strtolower($this->subdomains));
   $this->it = ltrim($_GET['it'], '/');

   // ...then your existing code…

}

public function ready() {
   // if $this->subdomain was valid in init(), then no need to do more here.
   if($this->subdomain) return; 

   $subdomain = $this->page->rootParent->name; 
   // if rootParent->name isn't a subdomain, then no need to continue
   if(!in_array($subdomain, $this->subdomainsArray)) return;

   // if subdomain is visible on url, we might wanna redirect
   if(strpos($this->it, $subdomain) === 0 && !$this->page->editable()) { 
    $url = str_replace("/{$subdomain}/", '/', $this->page->httpUrl);
    $this->session->redirect(url); 
   }
}

The point of this is to avoid sending an unfiltered $_GET['it'] into $pages->get(), which may contain anything in it at that point. There's always a security concern with sending unfiltered input to any function that isn't expecting it. You can avoid the issue completely by moving the check into the ready() function, which gets called after PW has already validated the URL and determined the page. If you wanted to get more fancy with it, you could also foreach($input->urlSegments) and append $input->pageNum (if > 1), but I really don't think that's necessary.

  • Like 1

Share this post


Link to post
Share on other sites

Nice, apeisa. Some multisite features would be a great enhancement for PW. For example to provide a mobile site using a subdomain. So this is a nice step forward here. I have been experimenting on something like this several weeks ago, too, but then had to focus on some other modules. So I’m curious about your ideas.

Share this post


Link to post
Share on other sites

Ryan, thanks for suggestion. For some reason I thought that $_GET['it'] has only path values like /fdas/asd/ (like htaccess wouldn't send it to pw otherwise) but of course that isn't the case (we can have get parameters in url). I will update my code soon.

Oliver: you could definitely use this for m.domain.com type of stuff, actually a great use case for this module also. Many of our clients tend to have multiple smaller sites, that need to use data from main site, are maintained by same people, but usually have different marketing domain and own visuals. That is the original need for this module, but actually I would probably use this for m.domain.com type of mobile versions also.

Share this post


Link to post
Share on other sites

Just pushed changes made by Ryan. They went in almost exactly like that.

  • Like 2

Share this post


Link to post
Share on other sites

Hi Atti, thanks for your module! I am a bit confused about the usage, though... How am I supposed to access the backend? The module rewrites the URL so I can access my pages under the domain page, but the admin page can't be moved inside this domain page. But without that I cannot access it because the URL domain.com/processwire/ is catched by the module and tries to redirect to domain.com/domain.com/processwire which fails.

Thx for help!

edit: I changed line 40 into:

if(strpos($httpHost, $subdomain) !== false && strpos($httpHost, 'admin') !== false) {

which works for now. But I think this is not intended, so I would appreciate the "proper" solution ;-)

Another edit: How is the homepage supposed to work? Now it is the root page, but with several domains it would be nice to have several homepages (under the domain page or the domain page itself). What do you think?

Edited by MadeMyDay

Share this post


Link to post
Share on other sites

This is how we use this:

www.maindomain.com // This is the mainsite, runs just like any other pw-site

www.campaign.com // This is the first one using multisite, this domain is entered into module settings, but also as page under maindomain.com

www.anothercampaign.com // Just like the above

Admin for all these pages is accessible from www.maindomain.com/processwire/

First level of site tree from maindomain.com looks like this:

  • About Us
  • News
  • Contact us
  • Sitemap
  • www.campaign.com (hidden)
  • www.anothercampaign.com (hidden)

I won't suggest building very complicated setups with this, but it is superb for few specific campaign sites (especially if same people maintain or they reuse the data between). If you have many big sites under same site, you will end up with huge amount of templates & fields.

  • Like 1

Share this post


Link to post
Share on other sites

I would like to ask if it could be possible for a site with this module to have "the same" pages urls or processwire won't allow it to be made in any way? What I mean by "the same" is domain.com/particular-page and domain.net/particular-page or m.domain.com/particular-page. It would be very useful ie in case of desktop and mobile websites.

So I suppose the question is if page in ProcessWire has to have unique Name or we might have got pages with the same names under different "Categories".

website.com/race1/first-place

website.com/race1/second-place

website.com/race2/first-place

website.com/race2/second-place

?

Share this post


Link to post
Share on other sites

I am not sure I fully understand your question. Page name needs to be unique only among siblings. So your described page-tree is perfectly valid.

If you were asking if this module is suitable for offering same content for differend devices, then it is not intention of this module and that could be done in template level.

Share this post


Link to post
Share on other sites

Ok, I just rechecked and everything is working fine. So sorry for unnecessary question. I must have been very asleep when messing with it this night. I was doing stupid mistake - cloning a page and wanting to set the same name without moving it in a tree earlier. But if I didn't ask I probably wouldn't check it again.

Thanks :)

Share this post


Link to post
Share on other sites

@apeisa, thanks for this module -- it's working beautifully!

For our needs I had to implement support for alternative domains (each extra domain can have n alternatives, which all point to the same location.) With separate domains for development and secure addresses -- not to mention that in this case the client required alternative domains that couldn't be handled very well with just redirects -- that was pretty much the easiest way to put together a consistent experience.

So, basically I'm asking if you'd be interested in incorporating that addition in the main module if I sent you a pull request for it (of course once I've tested it properly first?) :)

Share this post


Link to post
Share on other sites

Sure. How are alternative domains setup in the config? Ie. how does the textarea scales here? Just commas between the different urls where the first one maps to the actual page?

Share this post


Link to post
Share on other sites

Pretty much like that, though at the moment only space is supported separator. Should probably add support for commas too, now that you mentioned it :)

Share this post


Link to post
Share on other sites

Currently I'm trying to get this to work, but I'm seriously questioning if I'm using this right. What I initially thought that had to do the following steps:

1) Make sure all the traffic from www.seconddomain.com points to the home directory of the www.maindomain.com. (checked)

2) Install the module and make sure that www.seconddomain.com is added to the textarea. (checked)

3) Create a new page with the template 'home' with the title matching the domain - in this case www.seconddomain.com. Status of the page is published and hidden. (checked)

Then I thought I have to add another page to make this work:

4) Create a page with a template underneath the 'second' homepage called 'Testpage'. Status of the page is published.

I can reach the page using the following URL:

http://www.maindomain.com/www.seconddomain.com/testpage/

But I can't reach the page using this URL:

http://www.seconddomain.com/testpage/

Things I've noticed

1. When I try to reach www.seconddomain.com it displays a 404 error.

2. The other items (like the primary navigation) on rootlevel are changed to www.seconddomain.com.

Thinking

Then I starting thinking (just about then ;) ): is this supposed to work like this?

The idea

I got a very simple site with three pages and the client really liked to the idea to create some landing pages using other domains but using the same structure. Hence I thought apeisa's Multisite could be used here.

Many thanks for any thoughts!

Share this post


Link to post
Share on other sites

Arjen, sorry to hear about problems. Your setup seems right to me.

Just to confirm: if you do remove the domain from module settings, you can use www.seconddomain.com and browse the "root site" normally? Also www.maindomain.com/www.seconddomain.com/ works and you can access that page normally?

Then if you try www.seconddomain.com is the 404 error msg generated by PW or Apache? Does the module do any redirects? What is visible on addressbar? Feel free to PM me any additional details if you want me to take closer look.

Share this post


Link to post
Share on other sites

If I remove the domain from the module setting I can browse the root site normally.

If I browse:

http://www.maindomain.com/www.seconddomain.com/

it loads the seconddomain homepage.

The 404 error is generated by PW. It doesn't redirect when I try to reach:

http://www.seconddomain.com/testpage/

I am using this with some subdomains. Could that be the issue here? The root site is located at:

http://clientdomainname.clients.mysite.com/

I will PM you in a short moment.

Share this post


Link to post
Share on other sites

I did forget to update this: there was an actual issue that is fixed now on latest commit. Thanks Arjen for finding and Teppo for fixing!

  • Like 3

Share this post


Link to post
Share on other sites

Hi,

with Options #1: multiple sites with multiple databases how

Sites can't easily share data with each other, since they are running independently from one another.

is hard?

I've 4 sites:

HQ (advertising and redirect to one of the children, in the future this control the newsletter sending operation and the main events calendar)

\_ site2

\_ site3

\_ site4

Site2 have the most users and contents.

Sites 2,3,4 can share a couple of "translator user".

HQ news/events must be viewed also in 2, 3 and 4.

Site2 specific news/events must be viewed in HQ, 3 and 4.

Only this.

Thanks,

Marco

Share this post


Link to post
Share on other sites

Unless I misunderstand, i think the answer is actually the module that this thread is about. Option 1 is for multiple databases that don't share data. Option 2 (this module) is the one you'd want with multiple sites sharing data.

Share this post


Link to post
Share on other sites

Hi Ryan,

you are right.

All ok, but in the pros and cons docs says can't easily, so I imagine that this can be done.

Which is the best way to have private database and template but share few info (e.g. global news) between the sites?

Share this post


Link to post
Share on other sites
Which is the best way to have private database and template but share few info (e.g. global news) between the sites?

The problem with having multiple sites pulling and/or manipulating from the same database is that the two sites become dependent upon one another. If something needs to change with the data source, then both sites need to change. If one site becomes compromised, both sites are compromised.

When two sites need to talk to each other, regardless of platform, the best practice is to use JSON or XML web services.

For the example you mentioned, and in the context of ProcessWire, I would use RSS feeds. Generate a feed of the data you want to share using the RSS Feed Generator module. Then output it on another site using the RSS Feed Loader module. Now you have two sites easily sharing data in a bulletproof manner.

For more complex needs, you might also want to check out the Pages Web Service module.

  • Like 2

Share this post


Link to post
Share on other sites

I have a website where the multisite module by apeia is running smoothly. One thing I can't get to work is how to share accounts on multiple sites. I've created an extra role called 'subscriber'. When I check:

if ($user->hasRole("subscriber")) {
echo "This is a subscriber.";
}

It's echoed on the mainsite.com, but it returns nothing (empty) on the otherdomain.com.

Then I checked:

echo $user->name;

It returns the $user->name on the mainsite.com, but again empty (actually guest) on the otherdomain.com.

Is this a session thing? Any thoughts on how to make a user who is logged in on the mainsite.com is also logged in on the subdomain.com?

Thanks!

Share this post


Link to post
Share on other sites

Sessions are based on cookies, which are domain spesific. So you need some kind of single sign on solution to share sessions between the domains.

  • Like 1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By d'Hinnisdaël
      Happy new year, everybody 🥬
      I've been sitting on this Dashboard module I made for a client and finally came around to cleaning it up and releasing it to the wider public. This is how it looks.
      ProcessWire Dashboard

      If anyone is interested in trying this out, please go ahead! I'd love to get some feedback on it. If this proves useful and survives some real-world testing, I'll add this to the module directory.
      Download
      You can find the latest release on Github.
      Documentation
      Check out the documentation to get started. This is where you'll find information about included panel types and configuration options.
      Custom Panels
      My goal was to make it really simple to create custom panels. The easiest way to do that is to use the panel type template and have it render a file in your templates folder. This might be enough for 80% of all use cases. For anything more complex (FormBuilder submissions? Comments? Live chat?), you can add new panel types by creating modules that extend the DashboardPanel base class. Check out the documentation on custom panels or take a look at the HelloWorld panel to get started. I'm happy to merge any user-created modules into the main repo if they might be useful to more than a few people.
       Disclaimer
      This is a pre-release version. Please treat it as such — don't install it on production sites. Just making sure 🍇
      Roadmap
      These are the things I'm looking to implement myself at some point. The wishlist is a lot longer, but those are the 80/20 items that I probably won't regret spending time on.
      Improve documentation & add examples ⚙️ Panel types Google Analytics ⚙️ Add new page  🔥 Drafts 🔥 At a glance / Page counter 404s  Layout options Render multiple tabs per panel panel groups with heading and spacing between ✅ panel wrappers as grid item (e.g. stacked notices) ✅ Admin themes support AdminThemeReno and AdminThemeDefault ✅ Shortcuts panel add a table layout with icon, title & summary ✅ Chart panel add default styles for common chart types ✅ load chart data from JS file (currently passed as PHP array) Collection panel support image columns ✅ add buttons: view all & add new ✅
    • By Pip
      Hi everyone!
      I'm trying out the Login/Register module for my site. Noted that the module assigns the newly registered user to login-register role. 
      Once you modify the login-register role's permissions, particularly adding page-edit, the new member role will be set to guest. 
      Thing is I'd like to grant my new users the power to create their own pages. Any advice? 
      Thanks. 
    • By Gadgetto
      SnipWire - Snipcart integration for ProcessWire
      Snipcart is a powerful 3rd party, developer-first HTML/JavaScript shopping cart platform. SnipWire is the missing link between Snipcart and the content management framework ProcessWire.
      With SnipWire, you can quickly turn any ProcessWire site into a Snipcart online shop. The SnipWire plugin helps you to get your store up and running in no time. Detailed knowledge of the Snipcart system is not required.
      SnipWire is free and open source licensed under Mozilla Public License 2.0! A lot of work and effort has gone into development. It would be nice if you could donate an amount to support further development:

      Status update links (inside this thread) for SnipWire development
      2020-07-03 -- SnipWire 0.8.7 (beta) released! Fixes some small bugs and adds an indicator for TEST mode 2020-04-06 -- SnipWire 0.8.6 (beta) released! Adds support for Snipcart subscriptions and also fixes some problems 2020-03-21 -- SnipWire 0.8.5 (beta) released! Improves SnipWires webhooks interface and provides some other fixes and additions 2020-03-03 -- SnipWire 0.8.4 (beta) released! Improves compatibility for Windows based Systems. 2020-03-01 -- SnipWire 0.8.3 (beta) released! The installation and uninstallation process has been heavily revised. 2020-02-08 -- SnipWire 0.8.2 (beta) released! Added a feature to change the cart and catalogue currency by GET, POST or SESSION param 2020-02-03 -- SnipWire 0.8.1 (beta) released! All custom classes moved into their own namespaces. 2020-02-01 -- SnipWire is now available via ProcessWire's module directory! 2020-01-30 -- SnipWire 0.8.0 (beta) first public release! (module just submitted to the PW modules directory) 2020-01-28 -- added Custom Order Fields feature (first SnipWire release version is near!) 2020-01-21 -- Snipcart v3 - when will the new cart system be implemented? 2020-01-19 -- integrated taxes provider finished (+ very flexible shipping taxes handling) 2020-01-14 -- new date range picker, discount editor, order notifiactions, order statuses, and more ... 2019-11-15 -- orders filter, order details, download + resend invoices, refunds 2019-10-18 -- list filters, REST API improvements, new docs platform, and more ... 2019-08-08 -- dashboard interface, currency selector, managing Orders, Customers and Products, Added a WireTabs, refinded caching behavior 2019-06-15 -- taxes provider, shop templates update, multiCURL implementation, and more ... 2019-06-02 -- FieldtypeSnipWireTaxSelector 2019-05-25 -- SnipWire will be free and open source Plugin Key Features
      Fast and simple store setup Full integration of the Snipcart dashboard into the ProcessWire backend (no need to leave the ProcessWire admin area) Browse and manage orders, customers, discounts, abandoned carts, and more Multi currency support Custom order and cart fields Process refunds and send customer notifications from within the ProcessWire backend Process Abandoned Carts + sending messages to customers from within the ProcessWire backend Complete Snipcart webhooks integration (all events are hookable via ProcessWire hooks) Integrated taxes provider (which is more flexible then Snipcart own provider) Useful Links
      SnipWire in PW modules directory SnipWire Docs (please note that the documentation is a work in progress) SnipWire @GitHub (feature requests and suggestions for improvement are welcome - I also accept pull requests) Snipcart Website  

       
      ---- INITIAL POST FROM 2019-05-25 ----
       
    • By Sten
      Hello
      Till now I hacked something with the twig template but it works no more with new PW versions so I look forward to create a module. I am working on a site in multiple languages : French, English, Italian, German, Spanish, Portuguese, Hebrew, Russian. The new posts are entered in any language with a field for language. Till now, I got twig files to get the translations with constants defined for each part of the pages.
      So I'd like to create a module to include theses files added according to the url /fr/en/...
      Have you some observations to do before I begin about the direction to take ?
      Thank you
    • By ukyo
      Mystique Module for ProcessWire CMS/CMF
      Github repo : https://github.com/trk/Mystique
      Mystique module allow you to create dynamic fields and store dynamic fields data on database by using a config file.
      Requirements
      ProcessWire 3.0 or newer PHP 7.0 or newer FieldtypeMystique InputfieldMystique Installation
      Install the module from the modules directory:
      Via Composer:
      composer require trk/mystique Via git clone:
      cd your-processwire-project-folder/ cd site/modules/ git clone https://github.com/trk/Mystique.git Module in live reaction with your Mystique config file
      This mean if you remove a field from your config file, field will be removed from edit screen. As you see on youtube video.
      Using Mystique with your module or use different configs path, autoload need to be true for modules
      Default configs path is site/templates/configs/, and your config file name need to start with Mystique. and need to end with .php extension.
      Adding custom path not supporting anymore !
      // Add your custom path inside your module class`init` function, didn't tested outside public function init() { $path = __DIR__ . DIRECTORY_SEPARATOR . 'configs' . DIRECTORY_SEPARATOR; Mystique::add($path); } Mystique module will search site/modules/**/configs/Mystique.*.php and site/templates/Mystique.*.php paths for Mystique config files.
      All config files need to return a PHP ARRAY like examples.
      Usage almost same with ProcessWire Inputfield Api, only difference is set and showIf usage like on example.
      <?php namespace ProcessWire; /** * Resource : testing-mystique */ return [ 'title' => __('Testing Mystique'), 'fields' => [ 'text_field' => [ 'label' => __('You can use short named types'), 'description' => __('In file showIf working like example'), 'notes' => __('Also you can use $input->set() method'), 'type' => 'text', 'showIf' => [ 'another_text' => "=''" ], 'set' => [ 'showCount' => InputfieldText::showCountChars, 'maxlength' => 255 ], 'attr' => [ 'attr-foo' => 'bar', 'attr-bar' => 'foo' ] ], 'another_text' => [ 'label' => __('Another text field (default type is text)') ] ] ]; Example:
      site/templates/configs/Mystique.seo-fields.php <?php namespace ProcessWire; /** * Resource : seo-fields */ return [ 'title' => __('Seo fields'), 'fields' => [ 'window_title' => [ 'label' => __('Window title'), 'type' => Mystique::TEXT, // or InputfieldText 'useLanguages' => true, 'attr' => [ 'placeholder' => __('Enter a window title') ] ], 'navigation_title' => [ 'label' => __('Navigation title'), 'type' => Mystique::TEXT, // or InputfieldText 'useLanguages' => true, 'showIf' => [ 'window_title' => "!=''" ], 'attr' => [ 'placeholder' => __('Enter a navigation title') ] ], 'description' => [ 'label' => __('Description for search engines'), 'type' => Mystique::TEXTAREA, 'useLanguages' => true ], 'page_tpye' => [ 'label' => __('Type'), 'type' => Mystique::SELECT, 'options' => [ 'basic' => __('Basic page'), 'gallery' => __('Gallery'), 'blog' => __('Blog') ] ], 'show_on_nav' => [ 'label' => __('Display this page on navigation'), 'type' => Mystique::CHECKBOX ] ] ]; Searching data on Mystique field is limited. Because, Mystique saving data to database in json format. When you make search for Mystique field, operator not important. Operator will be changed with %= operator.
      Search example
      $navigationPages = pages()->find('my_mystique_field.show_on_nav=1'); $navigationPages = pages()->find('my_mystique_field.page_tpye=gallery');
×
×
  • Create New...