Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

luceos's avatar

Multi tenant packages

Latest Stable Version License Build Status Code Coverage StyleCI

Currently I'm working on some packages that will help with multi tenancy in Laravel 5+. As a lot of effort is already going into it and I see a lot of multi tenant discussions on this forum, I am wondering what you would prefer seeing in the first stable release.

I've documented all features on the project website, but in short it allows you to create a true distinction between tenants including databases, views, routes, service provides but also vendor packages using composer. I also plan (and have working) to support generation of webserver configurations and registration of the multi tenant laravel installation of any of those webservices.

My goal is to make the packages as unobtrusive as possible, allow for extreme flexibility without removing functionality from laravel.

From different other topics I gathered the following requests:

Please advise, aside from the current stability; would you have interest in such packages and what would you love to see in future releases. The project lives on http://hyn.me, is available on packagist and is open source under the MIT license (the same license as laravel). It's also not yet stable, but ready to be used ;)

0 likes
53 replies
luceos's avatar

Website was unavailable for a few seconds due to the update to laravel 5.1.1 ;)

graham's avatar

@luceos that looks like it has loads of potential. I'll definitely be testing it out when I get a couple of spare hours.

Will you come back and update the thread when you have your demo up and running?

1 like
andy's avatar

I favorited this thread and then saw what you were doing. I just had to come back and say that this is awesome!

Do you need all 3 packages to run this?

1 like
luceos's avatar

Wow, thanks for your support guys.

  • @graham "Will I update this thread (once the demo is up and running)?" If enough people are showing interest. Yes, no problem. I do not believe in fragmented topic-related communication channels. You can also subscribe to the monthly newsletter (no spam guaranteed). Also the demo in fact is already available, I made all objects read only; just visit https://hyn.me/management/websites for the first pages (websites & ssl certificates). Please note functionality is limited through the read only mode (also an option in the package) and some features might be broken due to the recent move to 5.1.1. I'm setting up a seperate dev machine as we speak.
  • @andy "Do you need all 3 packages to run this?" No absolutely not, you will need hyn-me/multi-tenant and that packages does require hyn-me/framework. All other packages (currently hyn-me/management-interface and hyn-me/webserver) are optional, in fact the framework package handles registration of all found service providers found for hyn-me packages. However those optional packages will add functionality that you might drool about :) Verifying whether a hostname is actually pointing to the machine for instance.
1 like
luceos's avatar

Yesterday evening and early this morning I have been working on setting up a seperate development machine. I ran into several issues while setting up the multi tenancy in laravel. Most of them have been resolved.

Resolved:

  • vendor packages seemed not be included for a tenant website
  • webserver configurations where written into the wrong folder
  • the setup command triggered many errors when no tables where yet existing

Something I will be working on in the near future:

  • support running migrations within tenant directories and vendor packages in tenant directories
  • run multi tenant migrations while running the setup command
  • create database and user for tenant (or allow custom settings)

So what does work?

  • Generation, modification and deletion of webserver files; includes Unique unix user, Nginx, PHP FPM, Apache and .. SSL certificates
  • Include webserver files in the webserver configuration
  • Creation of tenant website directories
  • Loading of possible routes.php (for routes definitions), providers.php (for service providers), vendor (using composer), config (for overruling application configuration -- unsure whether that is smart ;)), views (for tenant templates), trans (for translation files), cache, media (is made available as /media absolute url).
  • Setting up tenant database connection (still have to create a database and user)
  • and more I fail to list..
2 likes
LarsN's avatar

Nice, I was just looking for something like this. I think there will be a lot of interest in the near future now with the LTS for 5.1 => you will see more and more enterprise apps being created with a need for something like this.

My wish would be that you keep it as simple as possible and only focus on the must-have-features to get those stable and easy to implement and then with a growing user base add more features. Good luck!

1 like
luceos's avatar

Hi @LarsN thank you for your support. I agree with you. The origin of this concept was to built multi tenancy for media companies who built websites as from a conveyor belt. In fact I had a running version on an early version of laravel 4 which looked awful in the code but worked splendidly since created. Now with the LTS version and my own experience building a large scale enterprise application for a webhosting company I found it a very wise decision to make these packages for a more generic purpose ánd open source.

I'll let you know when the version is ready to be tested, I expect a preliminary RC to be available soon (as in a few days or maybe a week or two).

samsoft's avatar

Great, i'm currently working on develop a multi-tenant application for Universities, i've been searching the web for several methods and way. looking at your concept... its really great but i'll like to ask this... is this package going to allow different database for every tenant but the same schema,

Take a look at my recent post https://laracasts.com/discuss/channels/general-discussion/better-way-to-create-db-connect-on-the-fly

maybe you can help!

luceos's avatar

Hello @samsoft

  • every tenant website has his own database with whatever tables are necessary; by default laravel does not generate any. So I will not make any tables obligatory.
  • a database will be created for every tenant website on creation.

Looking at your post you will be able to do exactly the same with my code once it's stable. You would need to make your own added implementation because you use subdomains (I use any host, also multiple per website) and I guess you would need identical routes and database tables for all tenants, but that's no issue at all. If you are still waiting for a solution once my packages are stable, we might discuss how to support your goals by then.

samsoft's avatar

Thanks @luceos appreciate your quick comment... yes, i'll like to make use of your package but how soon can you get it to stable version??? my client is on me right now to deliver the project.

luceos's avatar

@samsoft I can't help you with your deadlines. My packages are a leisure time project and I cannot guarantee any release dates so far. So for you current project it might be best to implement your own solution.

Also you might use the development versions of the packages, but that would be at your own risk. And I cannot help you with integration for now as my effort is solely on releasing the stable versions.

luceos's avatar

I just send an email newsletter about progress in June. Stable version is closing in, work is focussed on supporting database generation for tenants and a setup artisan command that will allow you to set up the first tenant website.

1 like
jartaud's avatar

This looks great!

  • Will we have to duplicate things like Models, Controllers, Services for each tenant?
  • Say we have 3 sites where only stuff like the logo, the slogan, the contact address and of course their domain are different, so duplicating only some configuration files for each tenant will do the trick?
luceos's avatar

@jartaud

  • Duplication; no; you can define models, controllers and services just the same way you'd do it with a normal laravel installation now and all that will be available for the tenant. So let's say you define routes in the global routes file, these will be available to all tenant websites. Also if you'd define a tenant specific route to a global controller, that's no issue either.
  • A nice great example. It's easy. You include a default set of routes from somewhere, one of the tenant website directories for example or you make them global is this application serves no other websites. These will point to the same controller (globally available though). The template have injected variables that allow you to overrule your logo, slogan etc using those variables.
1 like
martinbean's avatar

@luceos How does your package deal with tenants’ assets (such as images, style sheets, views etc)?

luceos's avatar

@martinbean The tenant website structure has one folder media. Although all tenant websites are stored non-publicly (for the webserver) all the webserver configurations generated by the hyn-me/webserver package "mount" this media folder to any hostname pointing to the website.

For instance example.com/media/logo.png will point to storage/multi-tenant/1-example-com/media/logo.png. This is done from within the webserver configuration. You are free to fork my multi-tenant package and force the media folder to be in the /public folder.

The reason I place as much files as possible belonging to one tenant together is to measure disk usage appropriately and to allow (perhaps in a future release) ftp access to the tenant to his website files.

luceos's avatar

Ok say I made a dummy website that shows off the capabilities of one tenant website.

You will see how resources from /media are loaded in a template. You can also see some variables at work, like current hostname and website.

luceos's avatar

Seeing how much I've been using the (optional) package hyn-me/webserver for interaction with the server, I've started removing the dependancy on the integrated paid theme. As a replacement I decided to implement the twitter bootstrap material design. Once this is done I expect a first rc to be available soon; I expect a release within a week or two.

kazehaya's avatar

@luceos this is looking awesome!

How do you deal with site specific content like uploading images and re-size them to specific formats based on the site? And how do you allow the user specific content that is being viewed specific for there website in the admin panel? for example the option for multi language or one website has a module products. can you bind those modules to a user account? Would love to hear some more about this :)

luceos's avatar

@kazehaya wow.. those questions are very advanced. First off the hyn multi tenancy packages will be available as a first version. I can ensure you there will be things that might be revised based on feedback from developers feedback.

Why do I mention developers? The hyn packages are meant to be used on top of laravel by developers to further implement their goals for multi tenancy. That's why unobtrusive is my highest priority. Having said that, the hyn packages do not imitate wordpress like behavior like scaling images.

However.. I currently implemented a feature I developed long ago for myself using nginx. It uses a specific subdomain url to allow resizing. See for instance: http://image.tonklabbers.nl/resize/350/350/media//gallery/frontend/6/IMAG0112.jpg and http://image.tonklabbers.nl/resize/150/150/media//gallery/frontend/6/IMAG0112.jpg. I'm considering however to drop this feature because apache2 is way more stable than nginx/fpm.

To answer you question about uploading and resizing images. At this time the hyn packages have no responsibility whatsoever to place media in the correct folder. The developer would have to create such functionality. Ofcourse I will be adding functionality in future releases that helps you with the process, but not for the first release.

How would I show tenant website specific media files to be shown in the admin panel? At this time, I wouldn't. But if I would add this feature I'd probably have you choose one primary hostname that will be used to manage the system. This one webserver configuration will not have a single mount from /media to storage/multi-tenant/1-example-com, but will have additional public media folders pointing to each and every tenant website.

I'm not sure whether I answered you last question. I find it hard to understand it, would you please clarify:

And how do you allow the user specific content that is being viewed specific for there website in the admin panel? for example the option for multi language or one website has a module products. can you bind those modules to a user account?

luceos's avatar

I'm closing in on the release. Database creation works, I'll be spending time on creating some unit tests to verify functionality and ensure installation and set up will be non-blocking.

luceos's avatar

A minor update before the weekend:

  • changed license from CC-BY to MIT for all packages.
  • attempted to create automated unit tests for this package integrated in laravel, but failed; awaiting replies on the laracasts topic and the stackoverflow question. Judging from the lack of response it is an uncharted territory.
  • cleaned up code and finished the SetupCommand that helps you set up the multi tenancy package for usage.
  • started working on the management-interface package to remove the dependancy on the commercial paid license, but decided against finishing it for the first release as it's an optional package.
  • made hyn-me/webserver a required package for the multi-tenant package due to its responsibility of managing databases.
andy's avatar

This is really looking great! I love the progress that you have made.

Where are the install instructions? :smile:

andy's avatar

@luceos HI, I'm still working on going through your packages and have a few questions.

1.) how do you pronounce it?

2.) Can you set up only a single instance for a database instead having every thing completely separate?

My application is basically a simple CMS that needs to run on several subdomains where each subdomain will have their own content but users don't need to be separated. In other words, I'm using subdomains to separate content but not users.

Using Cars as an example:

toyota.domain (for articles on toyota cars and categories of makes)

honda.domain (the same for articles on Honda cars and categories of makes)

etc ...

3.) What is your framework package for?

Thanks!!

luceos's avatar

Hello @andy

  • hyn is pronounced as hine as "dine", in the end it's not important so call it whatever you like ;)
  • you can set the User model to use the hyn connection, all other objects can then use tenant connections, thus you will use authentication based on one central database, your subdomains can then easily store their own seperate content
  • framework is a seperation of the abstract classes used on multiple hyn packages, like webserver, multi-tenant and management-interface, it includes an abstract controller for example. Also, very important, it loads any service providers it can find that you might have installed from other hyn packages.
luceos's avatar

Together with some great people, of which @thijsvdanker certainly deserves credit for sending in some critical pull requests, we've managed to run over the first installation procedures. For those of you who'd like to try the package out (outside of production environments), it should be available and usable. Any issues can be reported at the github repository and will be resolves as soon as possible. I'd love to hear your opinions.

andy's avatar

This is really coming together! Nice :smile:

1 like
Next

Please or to participate in this conversation.