I have a Laravel 8 application. The session is not working if deployed on the subdomain.
For example, I have a domain "example.com
" and we have created two subdomains testapp.example.com
and app.example.com
for testing and staging environments.
When deploying the application on testapp.example.com
first we observed that session not working after that updated config/session.php
to set session domain = ".example.com"
. Initially, it was working after this change but when again the application deployed on "app.example.com
" session not working on testapp.example.com. It is working for "app.example.com". I want different sessions to be maintained on these different subdomains, dont want to share session between subdomain. Can anyone suggest?
Thanks.
You do not want to set that session domain, that is the session_domain configuration if you wish to share the sessions across subdomains. By default it will not. You need them to be set to app.example.com
and testapp.example.com
accordingly. This is the SESSION_DOMAIN
in the .env file
Alternatively you can simply change the SESSSION_COOKIE for each application. This is best set in the .env file as SESSION_COOKIE=testexample.com
or alternatively in config/session.php if you already modified the default laravel settings in there.