PHP Classes

Symfony Multi Tenant: Example of multi-tenant application using Symfony

Recommend this page to a friend!
  Info   View files Documentation   View files View files (45)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog (1)    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 52 This week: 1All time: 10,609 This week: 560Up
Version License PHP version Categories
symfony-multi-tenant 1.0.1The PHP License5PHP 5, Libraries
Description 

Author

This package provides an example of multi-tenant application using Symfony.

It provides a command class to use the Symfony console that can create new tenants of an application by creating a new configuration to set a new database or a new sub-domain to run the same application for a new tenant.

The application uses a separate directory for the central application code and a different directory for the tenant code.

Innovation Award
PHP Programming Innovation award winner
February 2023
Winner
Multi-tenant applications serve multiple users or customers running the same code base and various versions of the same application as if the applications are separate.

This type of application structure allows a single effort to address the needs of different customers with minimal measure of adaptation.

This package provides an example of a multi-tenant application using the Symfony framework to help other developers learn from this effort.

Manuel Lemos
Picture of Nyi Nyi Lwin
  Performance   Level  
Name: Nyi Nyi Lwin <contact>
Classes: 12 packages by
Country: Myanmar Myanmar
Age: 31
All time rank: 26745 in Myanmar Myanmar
Week rank: 106 Up1 in Myanmar Myanmar Up
Innovation award
Innovation award
Nominee: 7x

Winner: 4x

Documentation

Symfony Multi-tenant Example

This is a simple example of a multi-tenant application using Symfony 6.2

Installation

  1. Clone the repository
  2. Run `composer install`
  3. Update hostname in `.env`
  4. Run `bin/console doctrine:database:create`
  5. Run `bin/console doctrine:migrations:migrate`

Create a new tenant

  1. Run `bin/console app:tenant-create` to create a new tenant
  2. Run `bin/console app:tenant-migrate {tenantId}` to run migrations for a tenant
  3. Run `bin/console app:tenant-create-user {tenantId}` to create a new user for a tenant
  4. Run `bin/console app:tenant-maintenance {tenantId} {mode}` to enable or disable maintenance mode for a tenant

Todo

  • [ ] Add tenant events
  • [ ] Add tests

  Files folder image Files  
File Role Description
Files folder image.github (1 file)
Files folder imagebin (1 file)
Files folder imageconfig (4 files, 2 directories)
Files folder imagemigrations (2 directories)
Files folder imagepublic (1 file)
Files folder imagesrc (1 file, 2 directories)
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file docker-compose.override.yml Data Auxiliary data
Accessible without login Plain text file docker-compose.yml Data Auxiliary data
Accessible without login Plain text file README.md Doc. Documentation
Accessible without login Plain text file symfony.lock Data Auxiliary data

  Files folder image Files  /  .github  
File Role Description
  Accessible without login Plain text file FUNDING.yml Data Auxiliary data

  Files folder image Files  /  bin  
File Role Description
  Accessible without login Plain text file console Example Example script

  Files folder image Files  /  config  
File Role Description
Files folder imagepackages (9 files)
Files folder imageroutes (1 file)
  Plain text file bundles.php Class Class source
  Accessible without login Plain text file preload.php Aux. Auxiliary script
  Accessible without login Plain text file routes.yaml Data Auxiliary data
  Accessible without login Plain text file services.yaml Data Auxiliary data

  Files folder image Files  /  config  /  packages  
File Role Description
  Accessible without login Plain text file cache.yaml Data Auxiliary data
  Accessible without login Plain text file doctrine.yaml Data Auxiliary data
  Accessible without login Plain text file doctrine_migrations.yaml Data Auxiliary data
  Accessible without login Plain text file framework.yaml Data Auxiliary data
  Accessible without login Plain text file lexik_jwt_authentication.yaml Data Auxiliary data
  Accessible without login Plain text file monolog.yaml Data Auxiliary data
  Accessible without login Plain text file routing.yaml Data Auxiliary data
  Accessible without login Plain text file security.yaml Data Auxiliary data
  Accessible without login Plain text file translation.yaml Data Auxiliary data

  Files folder image Files  /  config  /  routes  
File Role Description
  Accessible without login Plain text file framework.yaml Data Auxiliary data

  Files folder image Files  /  migrations  
File Role Description
Files folder imageCentral (2 files)
Files folder imageTenant (2 files)

  Files folder image Files  /  migrations  /  Central  
File Role Description
  Plain text file Version20230110051740.php Class Class source
  Plain text file Version20230213094906.php Class Class source

  Files folder image Files  /  migrations  /  Tenant  
File Role Description
  Plain text file Version20230111165939.php Class Class source
  Plain text file Version20230213094906.php Class Class source

  Files folder image Files  /  public  
File Role Description
  Accessible without login Plain text file index.php Example Example script

  Files folder image Files  /  src  
File Role Description
Files folder imageCentral (8 directories)
Files folder imageTenant (3 directories)
  Plain text file Kernel.php Class Class source

  Files folder image Files  /  src  /  Central  
File Role Description
Files folder imageCommand (4 files)
Files folder imageController (1 file)
Files folder imageDoctrine (1 directory)
Files folder imageEntity (2 files)
Files folder imageEventSubscriber (1 file)
Files folder imageException (1 file)
Files folder imageRepository (2 files)
Files folder imageServices (1 file)

  Files folder image Files  /  src  /  Central  /  Command  
File Role Description
  Plain text file TenantCreateCommand.php Class Class source
  Plain text file TenantCreateUserCommand.php Class Class source
  Plain text file TenantMaintenanceCommand.php Class Class source
  Plain text file TenantMigrationCommand.php Class Class source

  Files folder image Files  /  src  /  Central  /  Controller  
File Role Description
  Plain text file WelcomeController.php Class Class source

  Files folder image Files  /  src  /  Central  /  Doctrine  
File Role Description
Files folder imageDBAL (1 file)

  Files folder image Files  /  src  /  Central  /  Doctrine  /  DBAL  
File Role Description
  Plain text file TenantConnection.php Class Class source

  Files folder image Files  /  src  /  Central  /  Entity  
File Role Description
  Plain text file Tenant.php Class Class source
  Plain text file User.php Class Class source

  Files folder image Files  /  src  /  Central  /  EventSubscriber  
File Role Description
  Plain text file TenantSubscriber.php Class Class source

  Files folder image Files  /  src  /  Central  /  Exception  
File Role Description
  Plain text file MaintenanceModeException.php Class Class source

  Files folder image Files  /  src  /  Central  /  Repository  
File Role Description
  Plain text file TenantRepository.php Class Class source
  Plain text file UserRepository.php Class Class source

  Files folder image Files  /  src  /  Central  /  Services  
File Role Description
  Plain text file TenantService.php Class Class source

  Files folder image Files  /  src  /  Tenant  
File Role Description
Files folder imageController (1 file)
Files folder imageEntity (2 files)
Files folder imageRepository (2 files)

  Files folder image Files  /  src  /  Tenant  /  Controller  
File Role Description
  Plain text file PostController.php Class Class source

  Files folder image Files  /  src  /  Tenant  /  Entity  
File Role Description
  Plain text file Post.php Class Class source
  Plain text file User.php Class Class source

  Files folder image Files  /  src  /  Tenant  /  Repository  
File Role Description
  Plain text file PostRepository.php Class Class source
  Plain text file UserRepository.php Class Class source

 Version Control Unique User Downloads Download Rankings  
 100%
Total:52
This week:1
All time:10,609
This week:560Up