gecche/laravel-multidomain
Run one Laravel codebase across multiple domains/tenants. Automatically load per-domain .env, storage paths, and database connections so each customer can have isolated config, data, and files while sharing the same application code.
site1.example.com, site2.example.com), aligning with Laravel’s single-codebase, multi-database/environment paradigm. This is ideal for SaaS platforms, white-label solutions, or shared-code deployments where tenants require isolated configurations (DB, storage, queues)..env.<domain>), dedicated storage paths (storage/<domain>), and domain-specific configs (e.g., queues, caches). This avoids cross-contamination between tenants while sharing the same codebase.Application, QueueServiceProvider) to ensure seamless domain detection via $_SERVER['SERVER_NAME'] (customizable). This minimizes friction with existing Laravel patterns (e.g., service providers, middleware).stancl/tenancy for schema-based isolation).storage:link) must be managed per-domain (workaround provided).app.php) and service providers (QueueServiceProvider), with minimal changes to existing code. The domain() helper method provides runtime access to the current tenant’s domain.--domain flags for commands (e.g., queue:work --domain=site1.com), enabling tenant-specific operations..env.<domain>.13.* for Laravel 13). Downgrading may require manual adjustments.HorizonServiceProvider (community-contributed)..htaccess rules or manual symlinks).bootstrap/app.php is non-standard and may conflict with:
app.php structure.$_SERVER['SERVER_NAME'] may be missing (e.g., CLI, some load balancers). Custom detection functions are provided but require manual setup.*.example.com). Requires middleware to validate domains against config/domains.php.storage:link per-domain. Workaround adds complexity (e.g., .htaccess hacks).chown -R www-data:www-data storage/site1_com).QUEUE_DEFAULT=site1_jobs). Misconfiguration can lead to job mixing..env.<domain> file, which could introduce minor overhead. Cache configs with php artisan config:cache --domain=<domain>.storage_path('app') → storage/site1_com/app) may impact filesystem operations.stancl/tenancy or middleware-based isolation instead..htaccess?Storage facade with domain-aware URLs?default) or dedicated queues (e.g., site1_jobs)?.env.<domain> files be managed in Git (e.g., .gitignore, secrets management)?Sentry tags, Laravel Debugbar filters)?app.php edits required). For Laravel 10–, manual overrides are needed.$_SERVER['SERVER_NAME'] (e.g., some shared hosts use localhost). Custom detection functions are provided but require testing.$_SERVER['SERVER_NAME'] is correctly passed (e.g., via nginx/traefik headers).stancl/tenancy).CACHE_DRIVER=redis in .env.<domain>). Redis can be shared or tenant-specific.QUEUE_CONNECTION=redis_site1).php artisan domain:add example.com).storage/example_com).QUEUE_CONNECTION=redis_site1).--domain flags.bootstrap/app.php and QueueServiceProvider.php artisan vendor:publish).php artisan domain:add test.example.com)..env to .env.<domain>.config/domains.php.| Component | Compatibility | Workarounds
How can I help you explore Laravel packages today?