Background

Around late 2017, I began developing a bespoke real estate system for a client of mine. Over the next year, it grew from a relatively straightforward CRM / CMS into a system that now supports the client’s entire business.

Last year, we reached a decision that the system was of sufficient quality that it could be made generic and spun off into a separate product we could sell. That process remains ongoing, but when I first started to think of approaches for its deployment, I began to encounter some obstacles...

The common thinking, is that you should use a multi-tenancy arrangement for your application, either with a single database’s records scoped to each tenant, or a separate DB for each client... of the two, I prefer the first option.

Learning how to implement multi-tenancy in Laravel is quite an involved process requiring a combination of middleware, Eloquent scopes and subdomain routing. The real issue I was facing though, actually had nothing to do with Laravel, but was related to SSL certificates & vanity urls.

For those unaware, a vanity URL refers to a means of allowing your clients to link their domain to the subdomain you've created for them on your app e.g. https://www.acme.com => https://acme.app.com

Enabling vanity URLs and coding the necessary routing within Laravel was all perfectly do-able. However, being able to do it with SSL security proved to be a nightmare. Essentially you’re masking a subdomain using another domain, which means the certificate ends up not pointing to the right place and is therefore rightly rejected by the browser.

There are ways around this, but they are either complicated, or require you to funnel your infrastructure through a third party. Combined with the inherent pitfalls of multi-tenancy, I decided to try a different approach…