Multi tenant Asset management

Your software
My Mautic version is: 4
My PHP version is: 8
My Database type and version is:

Your problem
My problem is: How can we configure the Mautic application asset directory to support multi-tenant support? For example: Tenant1 & Tenant2 are hosted on the same codebase but with different database architecture, in this case, how do we differentiate the asset sharing among those two tenants? When Tenant1 uploads any files they should be uploaded to the Tenant1 directory and the same for Tenant2. How can we achieve this?

These errors are showing in the log:

Steps I have tried to fix the problem:

Sharing the same folders while using different databases - it a supported setup that I’ve heard of, but let’s see: Surely you must be some sort of symlinking or other magic (for config, cache,…), right?
Did you not try using the same for assets?
Can you tell us about your setup in general? (Also: what’s the point in using a shared code approach, in your case?)

Hi, @ekke thanks for you response.

Our Infra setup is like this: We have a single codebase and multiple databases for each client.
Depending on the domain request from each client we will be switching/redirecting them to the respective database. This we have achieved with the reference from here: Implement Multi-tenancy In Mautic | Marketing Automation Solution

$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";

As we can see in the above code they are checking the domain request and based on that setting $local_config to map to that.

But I’m wondering how we configure the assets folder for every tenant differently in this way. What should be the path/config we have to alter it programmatically so that it will switch accordingly. It would be helpful if you can share some information on the same.
Thanks in Advance!

Oh wow, thanks - I never ran across that hack :slight_smile:

It is not mentioned in that “tutorial” but clearly you will want to define distinct folders e.g. for logs and caching via Configuration → System Settings
and just the same for Assets via Configuration → Asset Settings

Again, I never saw or tried this, I’m just giving my best guess.
But please keep us updated!

1 Like