Going Multi tenant with Mautic

Getting your Mautic instance setup for multi tenant is quick and easy. The benefit of this is that you have a single code base which you update and manage. The con is that this does take a little setup and is a little more complex, but it’s still easy to do.

Check out the Ultimate Mautic User Guide

Learn more about Mautic by reading the compressive guide that shows you how to setup and use Mautic to get more sales

Create a Database for each domain

You will need to create a database for each domain you want to host Mautic on. This can be done easily using cPanel on your shared hosting.

Generally, I will name the database after the domain. So for example, if Mautic is being hosted at example.com the database name I would use would be mautic_example.

Write a line of code

Once you have your databases setup, you will need to create the file app/config/paths_local.php.

<?php
// app/config/paths_local.php
$paths['local_config'] = '%kernel.root_dir%/config/local-'.$_SERVER['HTTP_HOST'].'.php';

Basically, all this file does is tell Mautic to use a config file based on the domain. For example, if Mautic was setup to be hosted at example.com it would use the config file local-example.com.php. If the file doesn’t exist, you will prompted to install and setup Mautic. (This is where you will enter in the database creds and the database name)

Cronjobs

Now the problem is when cronjobs run, Mautic doesn’t know which config file to load. This problem is pretty easy to fix by prefixing HTTP_HOST=”example.com” in front of the command. Here’s an example of a cron file

0,15,30,45 * * * * HTTP_HOST="example.com" php /path/to/mautic/bin/console mautic:segments:update > /dev/null
5,20,35,50 * * * * HTTP_HOST="example.com" php /path/to/mautic/bin/console mautic:campaigns:update > /dev/null
10,25,40,55 * * * * HTTP_HOST="example.com" php /path/to/mautic/bin/console mautic:campaigns:trigger > /dev/null
Scroll to Top