Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Laravel Multidomain Laravel Package

gecche/laravel-multidomain

Run one Laravel codebase across multiple domains/tenants. Automatically load a domain-specific .env, storage path, and database/config per customer, enabling isolated data and settings while sharing the same application and deployment.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Multi-Tenant Isolation: The package excels at database, storage, and configuration isolation per domain, aligning with multi-tenant SaaS architectures where shared code serves distinct customers.
  • Laravel-Centric: Deeply integrated with Laravel’s core (e.g., Application, QueueServiceProvider), ensuring minimal deviation from standard Laravel workflows.
  • Domain-Aware Routing: Leverages $_SERVER['SERVER_NAME'] (customizable) to dynamically load per-domain configs, enabling zero-code changes for domain-specific logic in most cases.
  • Storage Segmentation: Automatically isolates storage/ per domain (e.g., storage/site1_com/), reducing collision risks in file-based systems (e.g., uploaded files, caches).

Integration Feasibility

  • Low Friction for Laravel Apps: Requires only 3 manual steps (override Application, replace QueueServiceProvider, publish config), making it easy to adopt in existing projects.
  • Artisan Command Support: Extends CLI tools (domain:add, domain:remove, domain:update_env) for runtime management, reducing manual config edits.
  • Horizon Compatibility: Supports Laravel Horizon with a one-line override, critical for queue-heavy applications.
  • SPA/Static Asset Handling: Provides workarounds for domain-specific public storage (e.g., .htaccess hacks), though not natively supported.

Technical Risk

  • Bootstrap Override: Modifying bootstrap/app.php is invasive and may conflict with:
    • Custom Laravel bootstrapping logic.
    • Future Laravel version changes (e.g., Laravel 11+ simplifies this).
  • Domain Detection Edge Cases:
    • Relies on $_SERVER['SERVER_NAME'] by default, which may fail in:
      • Non-HTTP contexts (e.g., CLI, queues without --domain).
      • Shared hosting where $_SERVER is unreliable (requires custom detection logic).
    • Subdomains vs. Domains: Assumes site1.example.comsite2.example.com; may need regex or custom logic for complex routing.
  • Queue Isolation:
    • Database queues require manual setup (e.g., separate QUEUE_DEFAULT per domain) to avoid job mixing.
    • Sync driver lacks domain isolation (jobs run in the same process).
  • Storage Link Limitations:
    • storage:link is hardcoded to storage/, requiring manual symlinks for per-domain public assets.
  • Config Caching:
    • config:cache generates domain-specific config-*.php files, which may bloat storage for many domains.

Key Questions

  1. Domain Routing Complexity:
    • How will domains map to subdirectories (e.g., example.com/site1) vs. subdomains (e.g., site1.example.com)? Does the package support wildcard domains (e.g., *.example.com)?
  2. Performance Impact:
    • What’s the overhead of loading per-domain configs/storage on every request? Is config caching (config:cache) recommended for production?
  3. Queue Strategy:
    • For database queues, how will we ensure zero job collisions across domains? Will we use separate queue tables or queue namespaces?
  4. CI/CD Pipeline:
    • How will environment variables (e.g., APP_ENV) be managed in CI/CD for multi-domain deployments? Will we use domain:update_env or separate .env files?
  5. Backup/Disaster Recovery:
    • How will we backup/restore domain-specific storage/configs without affecting others? Are there atomic rollback mechanisms?
  6. Monitoring:
    • Can we tag metrics/logs (e.g., Prometheus, Sentry) by domain for per-tenant observability?
  7. Upgrade Path:
    • What’s the migration path if we later need to split into microservices? Will domain isolation hinder future decoupling?

Integration Approach

Stack Fit

  • Laravel Versions: Supports Laravel 5.5–13.x, but Laravel 10+ is recommended for active maintenance and simpler installation.
  • Queue Drivers:
    • Database/SQS/Redis: Fully supported with manual queue isolation required.
    • Sync: Not isolated (jobs run in the same process).
  • Storage Systems:
    • Local/Cloud (S3, etc.): Works with per-domain paths (e.g., storage/site1_com/).
    • Database Filesystem: Requires custom table prefixes or separate connections.
  • Caching:
    • File/Redis: Per-domain storage paths ensure isolation.
    • Database: May need separate cache tables or key namespacing (e.g., domain:site1:key).
  • Authentication:
    • Session/Token-Based: Works if storage is isolated (e.g., storage/site1_com/sessions).
    • Cookie Domains: May require .example.com wildcard or subdomain-specific cookies.

Migration Path

  1. Assessment Phase:
    • Audit current domain routing, queue usage, and storage dependencies.
    • Identify high-risk areas (e.g., shared queue tables, global storage links).
  2. Pilot Deployment:
    • Start with non-critical domains to test:
      • Domain detection (e.g., $_SERVER['HTTP_HOST'] vs. $_SERVER['SERVER_NAME']).
      • Queue isolation (e.g., separate QUEUE_DEFAULT per domain).
      • Storage segmentation (e.g., manual symlinks for public assets).
  3. Phased Rollout:
    • Phase 1: Add domains via domain:add and validate config/env isolation.
    • Phase 2: Migrate queues to domain-specific workers.
    • Phase 3: Update storage links and public asset handling.
  4. Fallback Plan:
    • For high-risk domains, maintain separate Laravel instances until isolation is proven.

Compatibility

Component Compatibility Workarounds
Laravel Core ✅ Full support (requires bootstrap override). Use Laravel 10+ for simpler setup.
Queues ⚠️ Database/SQS/Redis: Manual isolation needed. Sync: No isolation. Separate QUEUE_DEFAULT per domain; avoid sync driver for multi-tenant.
Storage ✅ Per-domain paths (e.g., storage/site1_com/). Manual symlinks for storage:link; customize filesystems.php.
Caching ✅ File/Redis: Isolated. Database: Manual namespacing needed. Use cache:table with domain-prefixed keys (e.g., domain:site1:key).
Auth ✅ Session isolation via per-domain storage. Ensure session.driver=file and storage paths are isolated.
Horizon ✅ Supported with one-line override. Replace HorizonApplicationServiceProvider.
SPA/Static Assets ❌ No native support. Use .htaccess or custom Nginx rules for domain-specific paths.
CI/CD ⚠️ Manual .env management unless using domain:update_env. Script domain:update_env in deployment pipelines.

Sequencing

  1. Bootstrap Override:
    • Replace Application and QueueServiceProvider before adding domains.
  2. Domain Setup:
    • Add domains via domain:add and configure per-domain .env files.
  3. Queue Configuration:
    • Update queue.php and set up domain-specific workers (e.g., --queue=site1).
  4. Storage Isolation:
    • Migrate public assets to domain-specific symlinks.
    • Update filesystems.php for custom public paths.
  5. Testing:
    • Validate domain detection, config isolation, and queue jobs.
  6. Monitoring:
    • Instrument metrics/logs with domain tags (e.g., domain=site1).

Operational Impact

Maintenance

  • Pros:
    • Centralized Domain Management: domain:add/remove/update_env commands reduce manual config edits.
    • Isolated Configs: Per-domain .env files minimize merge conflicts in shared repos.
    • Storage Segmentation: Reduces accidental data leaks between tenants.
  • Cons:
    • Config Caching Overhead: config:cache generates domain-specific files, increasing **storage
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui
babelqueue/php-sdk
facebook/capi-param-builder-php
babelqueue/symfony
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle