BillRun billing supports multi tenancy at the same instance.
The idea is to have multiple billing implementations that share the same codebase.
The support is enabled by adding new configurations and different databases and schemas for each tenant on the instance.
The assumption in this guide that the multi-tenancy is managed under billrun.localhost domain with sub-domains delivered with NGINX.
Adding to the nginx the next fastcgi_param setting:
fastcgi_param APPLICATION_MULTITENANT 1;
After the change applied, required to:
server_name: *.billrun.localhost;
/etc/hosts
More info about the nginx settings can be found under BillRun installation guide.
After this setting is enabled, the application identifies the tenant by the sub-domain. For example, if your domain is billrun.localhost, the tenant will be:
<TENANTNAME>.billrun.localhost
For running command-line, it's required to enable the multi-tenant settings:
export APPLICATION_MULTITENANT=1
Instead of running this option each time, it can be added to /etc/profile
file.
After enabling multi-tenancy, each command requires --tenant=<TENANTNAME>
. For example, running charge command:
php public/index.php --env prod --tenant <TENANTNAME> --charge --size 20000
For each tenant there are separate configurations as follows:
<BILLRUN_ROOT>/conf/tenant/<TENANTNAME>.ini
: for each tenant you can have separate configurations. Separate database is a must and is configured here.<BILLRUN_ROOT>/shared/<TENANTNAME>/
: for each tenant you will have a separate directory for invoices, payment files, workspace, etc.<BILLRUN_ROOT>/logs/<TENANTNAME>/
: for each tenant you will have a separate directory.<BILLRUN_ROOT>/application/views/invoices/tenants/<TENANTNAME>/
: for each tenant you will have a separate custom invoice design directory.<BILLRUN_ROOT>/conf/translations/tenants/<TENANTNAME>/
: for each tenant you will have a separate invoice translation overrides directory.<BILLRUN_ROOT>/cache/<TENANTNAME>_
: for each tenant you will have a separate cache prefix. Only if cache is enabled.Sample code to get the current tenant:
$currentTenant = Billrun_Factory::config()->getTenant();