Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel Multisite Setup with Sub Domains

I want to build Laravel CMS with following requirements:

  1. Admin (manage all sites/database).
  2. Multi-sites (running on sub-domains, manage own database) each with API access.
  3. Same Codebase (can be replicated if needed).
  4. Same Database with different data for each site.

Can you please let me know how to setup this environment using Laravel 5.4.

Thanks.

like image 973
Imran Ali Avatar asked Aug 02 '26 05:08

Imran Ali


1 Answers

This project has been finished now. So posting my own solution for the question.

Following are points to take care:

  • I've used Laravel 5.4 (later upgraded to 5.5).
  • For multi tenancy used Landlord extension for Laravel.
  • Server is configured to listen for wild-card sub-domains.
  • Each site is running on sub-domain.
  • Using single database with site-id (tenant-id) under each DB table.

Whenever server gets request, sub-domain is matched with tenant id in the middleware & load all the records for that tenant only.

I've hope this might help someone else.

like image 149
Imran Ali Avatar answered Aug 04 '26 18:08

Imran Ali