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

mustard's avatar

Share Laravel Auth Session Across Multiple Sub-domains From Same Repo using Forge

I am running a Laravel 5.7 (PHP 7.1) project that routes users to different sub-domains depending on their user role. I have the following setup:

id.domain.com => This is the auth domain which logs users in and redirects accordingly. admin.domain.com => this is the "CMS" and administration backend. customers.domain.com => this is the customers admin portal.

Currently the main domain.com URL is not part of the Laravel implementation and runs on a different platform.

All routing attaches the 'web' middleware and where application the 'auth' one. I am currently running database as my SESSION_DRIVER and have setup the SESSION_DOMAIN as ".domain.com".

When I run the project via Homestead - with each of the sub-domains as different sites in the YAML file all pointing to the same code base all pulling off the same ENV file - this works 100% correctly.

When I log in on id.domain.com it determines that I am 'admin' and redirects me to admin.domain.com and my Auth status remains intact.

PRODUCTION For production, I have set the A Records for each domain to point to the same Linode server. Each domain is then configured on Laravel Forge as separate sites. Each site pulls from the same code repo.

I have replicated the same ENV file and server setup for each site and they all share the same database and session table.

However, when I log in on id.domain.com - it authenticates me, redirects me to the admin domain, however that domain doesn't have my Auth status, so redirects me back to the ID domain, and a continuous loop occurs ending in too many redirects.

I have experimented with the same APP_KEY, different keys, changing the SESSION_DOMAIN, APP_DOMAIN, APP_URL - but with the same effect.

I am sure this is just a configuration issue somewhere - since the code base and logic works 100% perfectly on Homestead with local domains.

I have read so many answers surrounding passing the session manually across, changing various settings, etc. but nothing seems to be working.

Any assistance / guidance here would be hugely appreciated!

0 likes
0 replies

Please or to participate in this conversation.