Multi Tenant Backend (one codebase with multiple db)

Hi @daft and Everybody. I’m about to make OCMS backend multi tenant. I know there are multi tenancy laravel packages but I don’t need one more dependency. October has custom storage paths, custom file upload widget and so on… so even with those packages I would have to handle a lot of things myself.

Below is my check list to do. Do you know any other aspect which I have to take consideration? Thanks is advance for you answer.

  • Create a Middleware to switch tenant, connecting to correct db per tenant based on request’s host (subdomain or domain)

  • Store sessions in db instead of files

  • Separate file uploads per tenant (storage/app/uploads)

  • Separate uploaded media files per tenant (storage/app/media)

  • Separate cache per tenant (storage/framework/cache)

  • Separate logs per tenant (storage/logs)

  • Handle migrations per tenant

  • Handle scheduled jobs, console commands and queue jobs per tenant

Hi @danielbidala,

With everything you’re planning (separate DB, storage, media, cache, logs, jobs, etc.), at that point wouldn’t it be easier to just go with split installations? It might save you from having to maintain so many tenant-specific overrides inside a single codebase.

Many years ago I created plugin for exactly this.
I’m not sure it will not work with v4 (originally plugin was created for v1.1, and later updated for v2), but you can check it anyway.