PHPackages                             mapeveri/multi-tenancy-bundle - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. mapeveri/multi-tenancy-bundle

ActiveSymfony-bundle[Database &amp; ORM](/categories/database)

mapeveri/multi-tenancy-bundle
=============================

Multi-tenancy, is a package for symfony and doctrine to manage tenants in a simple way.

1.0.1.x-dev(4y ago)1175[1 issues](https://github.com/mapeveri/multi-tenancy-bundle/issues)MITPHPPHP &gt;=7.3

Since Nov 7Pushed 1y ago3 watchersCompare

[ Source](https://github.com/mapeveri/multi-tenancy-bundle)[ Packagist](https://packagist.org/packages/mapeveri/multi-tenancy-bundle)[ Docs](https://github.com/mapeveri/multi-tenancy-bundle)[ RSS](/packages/mapeveri-multi-tenancy-bundle/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependencies (13)Versions (2)Used By (0)

multi-tenancy-bundle
====================

[](#multi-tenancy-bundle)

**WARNING: this repo is not maintained anymore**

Symfony bundle for multiple tenancy.

Multi-tenancy, is a package for symfony and doctrine to manage tenants in a simple way. The package has 2 main entities:

- Tenant
- Hostname

Basically a **tenant** is the way to reuse your default code and a **hostname** is the FQDN (Fully Qualified Domain Name) for example: tenant.example.com, the bundle set the tenancy connection based on this FQDN.

Installation
------------

[](#installation)

Via composer

```
    composer require mapeveri/multi-tenancy-bundle
```

Configuration
-------------

[](#configuration)

1. Configuration .env file

Mysql

```
DATABASE_URL="mysql://user:password8@127.0.0.1:3306/databaseName?serverVersion=5.7&charset=utf8"
DATABASE_TENANT_URL=${DATABASE_URL}
```

PostgreSql

```
DATABASE_URL="postgresql://user:password@localhost:5432/databaseName?charset=utf8"
DATABASE_TENANT_URL=${DATABASE_URL}
```

2. doctrine.yaml configuration

Mysql:

```
doctrine:
    dbal:
        default_connection: default
        connections:
            default:
                url: '%env(resolve:DATABASE_URL)%'
                driver: 'pdo_mysql'
                server_version: '5.7'
                charset: utf8mb4

            tenant:
                driver: 'pdo_mysql'
                server_version: '5.7'
                charset: utf8mb4
                url: '%env(resolve:DATABASE_TENANT_URL)%'
                wrapper_class: MultiTenancyBundle\Doctrine\DBAL\TenantConnectionWrapper

    orm:
        default_entity_manager: default
        entity_managers:
            default:
                connection: default
                mappings:
                    Main:
                        is_bundle: false
                        type: annotation
                        dir: '%kernel.project_dir%/src/Entity/Main'
                        prefix: 'App\Entity\Main'
                        alias: Main
                    MultiTenancyBundle:
                        is_bundle: true
                        type: annotation
                        dir: 'Entity'
                        prefix: 'MultiTenancyBundle\Entity'
                        alias: MultiTenant
            tenant:
                connection: tenant
                mappings:
                    Tenant:
                        is_bundle: false
                        type: annotation
                        dir: '%kernel.project_dir%/src/Entity/Tenant'
                        prefix: 'App\Entity\Tenant'
                        alias: Tenant
```

PostgreSql:

```
doctrine:
    dbal:
        default_connection: default
        connections:
            default:
                url: '%env(resolve:DATABASE_URL)%'
                driver: 'pdo_psql'
                server_version: '12.8'
                charset: utf8mb4

            tenant:
                driver: 'pdo_psql'
                server_version: '12.8'
                charset: utf8mb4
                schema_filter: ~^(?!public)~
                url: '%env(resolve:DATABASE_TENANT_URL)%'
                wrapper_class: MultiTenancyBundle\Doctrine\DBAL\TenantConnectionWrapper

    orm:
        default_entity_manager: default
        entity_managers:
            default:
                connection: default
                mappings:
                    Main:
                        is_bundle: false
                        type: annotation
                        dir: '%kernel.project_dir%/src/Entity/Main'
                        prefix: 'App\Entity\Main'
                        alias: Main
                    MultiTenancyBundle:
                        is_bundle: true
                        type: annotation
                        dir: 'Entity'
                        prefix: 'MultiTenancyBundle\Entity'
                        alias: MultiTenant
            tenant:
                connection: tenant
                mappings:
                    Tenant:
                        is_bundle: false
                        type: annotation
                        dir: '%kernel.project_dir%/src/Entity/Tenant'
                        prefix: 'App\Entity\Tenant'
                        alias: Tenant
```

3. Configuration to doctrine\_migrations.yaml

```
doctrine_migrations:
  migrations_paths:
    'DoctrineMigrations': 'migrations/Main'
    'DoctrineMigrationsTenant': 'migrations/Tenant'
```

**It's important to keep** DoctrineMigrations and DoctrineMigrationsTenant namespaces.

4. Add the bundle to bundles.php

```
return [
    ...
    MultiTenancyBundle\MultiTenancyBundle::class => ['all' => true],
    ...
];
```

Commands for main database
--------------------------

[](#commands-for-main-database)

In this case we can use doctrine commands:

```
    php bin/console doctrine:migrations:status
```

```
    php bin/console doctrine:migrations:diff
```

```
    php bin/console doctrine:migrations:migrate
```

Commands for tenants
--------------------

[](#commands-for-tenants)

Genarate migrations

```
    php bin/console tenancy:diff tenant
```

Status migrations

```
    php bin/console tenancy:status tenant --tenant=tenant1
```

Migrate single tenant

```
    php bin/console tenancy:migrate tenant --tenant=tenant1
```

Migrate all tenants

```
    php bin/console tenancy:migrate tenant
```

In all cases the first parameter is the entity manager name and the option --tenant is the tenant name.

Supported databases
-------------------

[](#supported-databases)

Right now it works with MySql and PostgreSql.

Usage
-----

[](#usage)

Create a new tenant:

```
        $entityManager = $this->getDoctrine()->getManager();

        $tenant = new Tenant();
        $uuid = Uuid::v4();
        $tenant->setUuid($uuid->toRfc4122());
        $entityManager->persist($tenant);
        $entityManager->flush();

        $hostname = new Hostname();
        $hostname->setTenant($tenant);
        $hostname->setFqdn("tenant1");

        $entityManager->persist($hostname);
        $entityManager->flush();
```

Remove a tenant:

```
        $doctrine = $this->getDoctrine();
        $entityManager = $doctrine->getManager();

        $hostname = $doctrine
            ->getRepository(Hostname::class)
            ->find($hostId);
        $entityManager->remove($hostname);

        $tenant = $doctrine
            ->getRepository(Tenant::class)
            ->find($tenantId);

        $entityManager->remove($tenant);
        $entityManager->flush();
```

Events
------

[](#events)

The bundle use the event dispatcher component to dispatch events, which are: MultiTenancyEvents::TENANT\_CREATED and MultiTenancyEvents::TENANT\_REMOVED.

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance33

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity31

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

1647d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/b90876157f30527e520eaf02b9152506173ed76d1e7e593ee7202b00f9e4256b?d=identicon)[mapeveri](/maintainers/mapeveri)

---

Top Contributors

[![mapeveri](https://avatars.githubusercontent.com/u/6276555?v=4)](https://github.com/mapeveri "mapeveri (25 commits)")

---

Tags

phpsymfonybundledoctrinemulti-tenancy

### Embed Badge

![Health badge](/badges/mapeveri-multi-tenancy-bundle/health.svg)

```
[![Health](https://phpackages.com/badges/mapeveri-multi-tenancy-bundle/health.svg)](https://phpackages.com/packages/mapeveri-multi-tenancy-bundle)
```

###  Alternatives

[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.4k5.6M651](/packages/sylius-sylius)[sulu/sulu

Core framework that implements the functionality of the Sulu content management system

1.3k1.3M152](/packages/sulu-sulu)[prestashop/prestashop

PrestaShop is an Open Source e-commerce platform, committed to providing the best shopping cart experience for both merchants and customers.

9.0k15.4k](/packages/prestashop-prestashop)[ec-cube/ec-cube

EC-CUBE EC open platform.

78527.0k1](/packages/ec-cube-ec-cube)[open-dxp/opendxp

Content &amp; Product Management Framework (CMS/PIM)

7310.3k29](/packages/open-dxp-opendxp)[kimai/kimai

Kimai - Time Tracking

4.6k7.4k1](/packages/kimai-kimai)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
