Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

inamali's avatar

Using custom domains and sub-domains with Multi-Tenant SaaS App using TenancyForLaravel

Hi, I am pretty new to building SaaS application and I am using Stencl TenancyForLaravel package to do the heavyLifting. My application is working fine on my localhost with sub-domains. However, I am curious how it will behave on the live server. Do I need to register each sub-domain in the DNS record for each Tenant or it will behave the same as it is on my localhost without any extra config on hosting ? Also, If I'd like to change the sub-domain to custom domain, then what additional steps do I need to perform to run the app for Tenant as it was on sub-domain ? P.S : my hosting is DigitalOcean.

1 like
9 replies
enoch91's avatar

For each tenant's sub-domain, you need to configure DNS records to point to your server's IP address. that's creating A or CNAME records for each sub-domain.

Configure your web server e.g., Nginx, or Apache to handle the incoming requests. Each sub-domain should be directed to your Laravel application.

If you are using HTTPS, make sure to obtain SSL/TLS certificates for each sub-domain. Let's Encrypt can get you free certificates.

Lastly, If you want to allow tenants to use custom domains, you'll need to implement domain mapping in your application. That's storing the custom domain associations in your database and dynamically handling requests based on the mapped domains.

inamali's avatar

@enoch91 Do I have to add entry for each tenant separately in the DNS or wildcard character would redirect every request to my server in case of sub-domains ? And If I use wildcard character for my sub-domains, then how can I add custom domain mapping in my hosting to redirect request to my application ?

enoch91's avatar

@inamali You can either add an individual entry for each tenant or a wildcard character, using a wildcard entry simplifies DNS configuration. However, it also means that any sub-domain will point to your server. This might be desirable or not depending on your use case. Also, If you choose a wildcard entry, you need to handle the logic of determining the correct tenant in your Laravel application. Stancl/Tenancy or your custom logic should identify the requested sub-domain and associate it with the correct tenant.

For custom domain mapping, you can refer to this Laracasts post

inamali's avatar

@enoch91 I understood your concern regarding subdomains, but for custom domains still didn't get the answer. I mean if I am to use wildcard subdomains then how would I map my custom domain to subdomain using CNAME.

enoch91's avatar
enoch91
Best Answer
Level 2

@inamali When a tenant wants to use a custom domain e.g. customdomain.com, you need to set up a CNAME record in their DNS settings pointing to your wildcard subdomain you created like this

customdomain.com    IN CNAME   tenant1.yourdomain.com

this means that requests to customdomain.com should be directed to the same IP address as tenant1.yourdomain.com

1 like
inamali's avatar

@enoch91 So I need to ask my customers to setup CNAME in their DNS to point to my subdomain ? is it right ?

enoch91's avatar

@inamali Yes please, except you have access to their domain configuration, then you can handle that yourself. hope this helps

1 like
inamali's avatar

@enoch91 I believe if that is something which is dependent on the user end, then I think I shouldn't touch that. Also different domain providers would have different configuration files, in such case, I'd leave that to users to point to my subdomain. Anyhow, you have been helpful and shared an insight on how to overcome this problem. Thank you soo much and much appreciated for your cooperation.

Please or to participate in this conversation.