Multi-Tenancy in Mautic this simple?

Is multi-tenancy literally this simple? Would doing the following allow one installation of mautic to work with multiple websites with no issues? (First party cookies delivered, reports, logs, etc, everything separate? – everything functioning just like separate installations of Mautic for each site?).

If so, I don’t understand all the issues / difficulties people talk about surrounding multiple containers managing multiple Mautic instances, etc, to try and do this? Or perhaps this is fine for one person running their own sites (which is what I’m looking to do), but not practical for agencies who need to keep things totally separate?

Taken from: How To Implement Multi-tenancy In Mautic

Implement Multi-tenancy in Mautic

  • Create a new empty database named as “main_db”.
  • Then create table named “tenant” which will hold details about all tenants.
  • It will have 3 fields including site_name, url and db_name as shown in figure

  • After that open mautic/app/paths.php file and add this code:
$host = $_SERVER["HTTP_HOST"];
$dbName = "main_db";
$conn =  mysqli_connect($servername , $username , $password, $dbName);
$sql = "SELECT * from `tenant` where url = {$host}";
$result = mysqli_query($conn, $sql);
$Arr = mysqli_fetch_array($result,MYSQLI_ASSOC);
$tenant = $Arr["site_name"];
$local_config = "%kernel.root_dir%/config/local_".$siteName.".php";
  • This will select corresponding config file on the basis of URL path.
  • Then copy database of current Mautic installation and use it for new tenant.
  • After that, create copy of mautic/app/config/local.php and rename it to [site_name].php.
  • Finally update database name, host, password and user according to the new database.
2 Likes

I’m a little confused…

Using this approach, wouldn’t you still have all of the tenants’ data in the same tables? For example, wouldn’t the Contacts table have the contacts for every tenant? If so, I don’t think that’s a very good way (well at least not a scalable way) to do it…

I think a “true” multi-tenant application should give each tenant their own schema/tables in the database, and should limit the the number of universal tables.

I’m not an expert, just trying to research and implement … but my understanding is that if each site is using different Mautic databases (although using one Mautic install), all Mautic related information for each particular site (which would include contacts and everthing else?) would be maintained in those separate databases? In other words, the experience would be just like having separate Mautic installations for each site?

In my situation, I simply want to manage my own sites with one Mautic installation (for lower VPS requirements and costs), so I’m not concerned about keeping things truly separate, although I don’t see a problem in using this method (if indeed this method works as stated, hence the query of my post) in general for those who do want multi-tenancy and to manage all in one installation of Mautic … as it seems to me if you ever want to migrate one site to a separate server and Mautic install, you could just export the required Mautic databases and such and do that?

Ahhh okay, I think I see what you did.

So the tenants table allocates an individual database (via db_name) to each tenant site?

I don’t see why that wouldn’t work, in general. Though I’m far from an expert on Mautic.

Just to clarify, I did not come up with the idea I linked to above. Someone referred to that in an older post and I’m just referring to it again now. Hopefully someone who has more experience will be able to join the discussion and let us know if it is indeed viable and why, perhaps, it’s not more discussed as it seems like a solution that would easily solve many mautic users desire to have one mautic install working properly for multiple websites (without the need for plugins and changing email headers and such) in order to save hosting resources.

I saw this solution before, and I always wondered how the upgrade process looks like when it comes to migrations.

1 Like

Thanks for your comment, Joey. I was looking at your plugin which seems to seek to solve the same issue (from the standpoint of sending the emails), but this solution (if viable?) might be a way to not need a plugin, but maintain each site-specific database information separately, thus Mautic could function as it was intended (one site, and specific databases and configs only for that specific site), thus eliminating the complexities of sending emails (with proper headers for first party cookies, etc) and the need to deal with database information that shouldn’t be mixed together (maintaining site-specific contacts and data separately).

Doesn’t Mautic only have a few databases and config files (as pointed out in the above solution) that hold all the specific site / user data? If it came time to migrate, isn’t it simply a matter of gathering those few databases and config files and reverting them to the original, single-site conventions (if indeed a single site-related mautic instance was to be extracted from the pool and set on it’s own somewhere else)?

Since the solution in this proposal is a very quick and clear modification, it seems to me that, for someone more knowledgeable than me, it wouldn’t be too difficult to ensure (with future upgrades) that some new convention doesn’t impact this configuration and if it does, would probably just take a slight adjustment? If this is the case, what a benefit to the community if someone would make this clear?

I think each Mautic SAAS provider has it’s own way to manage this.
We have our own software that creates / updates / manages Mautics installed in separate LXD containers (like they would be installed on separate VPS)

You can do this manually up to 10-15 clients, but if you have over 50 it starts to be tricky, thatswhy you need a software.

This solution you provide might be okay, I have never tried it. All your Mautics will be forced to be in the same environment, and you have no chance to update just one client. You have to do all or nothing all the time.

Joey

This is similar to what I have done for our own sites (not a SaaS provider, just running our own sites). I used Proxmox, which easily allows for creating, configuring and managing LXC containers, each running Mautic, help desk software etc. It’s served our purposes nicely though I wouldn’t recommend it for anyone who doesn’t have some Linux skills.

So with your setup, you’re saying you host each Mautic instance on its own LXC?

Yes exactly

Yep same here. Clear separation.
I don’t use proxmox due to its limitations, but if you don’t want to learn how lxc via command line works, it’s a very good alternative.

Hi Bob… I see Proxmox has a GUI. Could someone figure it out with Google and some good research?

I just tried Cyberpanel and although I love the features, (containerization, docker compatability, one click Mautic install, etc), but I kept running in to bugs (in regard to basic configurations with ssl certificates, etc) which becamse a show stopper … so I’m looking for a replacement panel that’s stable – preferably open source / free.

I can fanangle my way around with some linux commands and googling, but if it’s too deep, I’m definitely not that familiar with Linux already.

Also, with multiple instances of Mautic vs using one install, I assume the server resources require doubling for each instance? Or does it have more to do with how many contacts in each installation? I don’t mind running multiple instances with containerization, I’m just worried about the server resources required.

The server resources are pooled. (unless you set otherwise).
Which is even better for your clients.

1 Like

Hi Joey. For example, don’t three instances of Mautic installations require three installations of Ubuntu 22 (or whatever your’re running) and doesn’t that multiply your server requirements x 3 as opposed to one installation of Mautic in one instance of Ubuntu 22? Perhaps my knowledge on this is limited, but I’d love to be pointed in the right direction of how to implement it otherwise, because I’d love to run a few instances of Mautic for our non-profit and personal sites and am looking for the best way to streamline and do it. Thank you!

If you have a 4 Core, 8 GIG Server, and install 4 containers:

  1. Haproxy to route traffic
  2. Ubuntu 22.04 Mautic 1.
  3. Ubuntu 22.04 Mautic 2.
  4. Ubuntu 22.04 Mautic 3.

Then all of these will share the resources of the server. Normally you wouldn’t designate resources to each container separately.
If all your containers run heavy task simultaniously, then you see that in the resources. But normally you wouldn’t notice in case of personal and small project mautics.

Just one more note:
The +3 x Ubuntu 22.04 overhead is not significant, it’s not like they need 4x the resources.

Thanks. Yes, I realize about all processes on a server sharing server resources; I meant three separate installs of unbuntu and three separate installs of Mautic, vs one of each = more RAM and CPU’s needed … It would be fantastic if one day Mautic could operate like Matomo – able to have different databases for different websites, instead of needing separate installs on separate OS instances for more than one website. Hence my initial query about the solution in the first post… BUT, until that solution is confirmed as a good one, I’m definitely open to finding out the best way to do this… My small need thus far was able to get away with 1 core and 1gb (or was it 2, can’t remember now) of RAM.

Hi Joey. What are the limitiations you mentioned re: proxmox? And are there other GUI recomendations you’d have? PURE command line might be too big a step for me at this stage. Although occasional terminal work would be ok (with google and youtube nearby for advice).

A server with 1-2 Gb of ram will cost $15-$20 usd / month.
4 Gb will cost around $30-$40 usd / month.

You don’t have to have a separate machine (real or virtual) in order to support multiple mautic instances, as JoeyK stated.

Using HAProxy for this would be wicked overkill, and certainly isn’t the way I would do it. If you only have a handful of Mautic instances to host, you could just have a single (Ubuntu, Debian, whatever) VM and install Virtualmin/Webmin. If you wanted to use that server to support other VMs/containers, then sure, but if all you want to do is host some Mautic instances, there are better ways to do that, in my opinion.

Virtualmin/Webmin are open source management software used to manage Linux servers. It provides a web UI, and in the paid versions, even includes an automatic installer script to install Mautic in a few clicks. But, even without the paid version, it’s very simple to install a new instance.

One thing that it wouldn’t do, which HAProxy, or some other virtualization platform would, is things like limiting iops/memory/cpu to the individual mautic instances. You can limit the size of the database for each instance, and the amount of storage, however.