Laravel 419 Page Expired on Login in Production: Fix
Login works locally but returns 419 Page Expired on your live Laravel site? Check cookies, HTTPS, session storage, load balancers and cached pages in the right order.
A Laravel 419 Page Expired error means the CSRF token sent with the form did not match the token stored in the user's session. On a live site that almost always means the session was lost between the page load and the form submit. Check that the session cookie is set and sent back, that SESSION_SECURE_COOKIE and SESSION_DOMAIN match your real URL, that the session store is shared by every server, and that no cache serves an old copy of the login page.
The 419 error is easy to miss in your own testing because it needs a real production setup: HTTPS, a proxy, more than one server, or a CDN. This guide goes through the causes in the order that finds the problem fastest. Every step takes a few minutes and needs no extra tools.
Step 1: Confirm It Is a Session Problem
Laravel protects every POST, PUT, PATCH and DELETE web request with the VerifyCsrfToken middleware. The token lives in the session. If the session is empty or different, the check fails and Laravel returns 419.
Open your browser dev tools, go to the Network tab and load the login page. Look at the response headers of the page request. You should see a Set-Cookie header for the session cookie (named after your APP_NAME, for example my_app_session) and one for XSRF-TOKEN.
Then submit the form and look at the request headers. Is the session cookie sent back?
- Cookie not set on the page response: the problem is on the server (Steps 3, 4 and 5).
- Cookie set but not sent back on submit: the browser rejected it (Step 2).
- Cookie sent back but still 419: the server cannot find the session, or the page was cached (Steps 4, 5 and 6).
Also check that your form has @csrf inside it. Without it, Laravel never receives a token. See the Laravel CSRF docs for the exact behaviour.
Step 2: Check the Cookie Settings Against Your Real URL
Open config/session.php and look at the values behind these environment variables:
APP_URL=https://app.example.com
SESSION_DOMAIN=null
SESSION_SECURE_COOKIE=true
SESSION_SAME_SITE=lax
The common mistakes:
SESSION_SECURE_COOKIE=truewhile the site is opened over plainhttp://. The browser drops a secure cookie on an insecure connection. This is a frequent answer in Stack Overflow threads about 419.SESSION_DOMAINset to a domain that does not match the one in the address bar, for example.example.comin.envwhile you test onstaging.other.com. Leave it asnullunless you share sessions across subdomains.SameSite=laxwhen the login form is inside an iframe or posted from another site. In that case the cookie needsSameSite=noneandSecure.- Browser or extension blocking third party cookies when the app is embedded.
Test in a clean private window with extensions off. If it works there, the first window had a stale or blocked cookie.
Step 3: Clear the Config Cache
If you run php artisan config:cache on deploy, Laravel reads configuration from the cached file and ignores later changes to .env. You can fix SESSION_DOMAIN and still see the old behaviour.
php artisan config:clear
php artisan config:cache
Do this after every .env change on a server that caches config. It also helps to restart PHP-FPM so opcache drops old files.
Step 4: Make Sure the Server Can Write and Share Sessions
With the file session driver, sessions are files in storage/framework/sessions. Two things break this in production:
- The web user (often
www-data) cannot write tostorage/andbootstrap/cache/. After a deploy by a different user, the folder owner changes and sessions silently fail. - You run two or more servers or containers behind a load balancer. Server A saves the session, the next request lands on server B, which has no such file. The login page loads, the form posts to another server, and you get 419 about half the time.
Check permissions first:
ls -ld storage storage/framework/sessions
sudo chown -R www-data:www-data storage bootstrap/cache
For more than one server, move sessions to a shared store. The database driver is the simplest:
php artisan session:table
php artisan migrate
SESSION_DRIVER=database
Redis also works with SESSION_DRIVER=redis. Newer Laravel versions already default to the database driver, but older projects upgraded in place often still use file. A random 419 that gets worse when you scale from one container to two is the classic sign.
Step 5: Fix HTTPS Detection Behind a Proxy
If a load balancer, Nginx or a platform terminates TLS and forwards plain HTTP to PHP, Laravel may think the request is insecure. It then generates http:// URLs and can mishandle secure cookies and redirects. A login that redirects from https to http and drops the cookie ends in 419.
Tell Laravel to trust your proxy. In Laravel 11 and newer, in bootstrap/app.php:
->withMiddleware(function (Middleware $middleware) {
$middleware->trustProxies(at: '*');
})
In older versions, set $proxies in app/Http/Middleware/TrustProxies.php. Use the real proxy IPs instead of * if you know them. Make sure the proxy sends X-Forwarded-Proto. The Laravel request docs on trusting proxies explain the headers.
Step 6: Stop Caching the Login Page
A CSRF token is unique per session. If a CDN or page cache stores the HTML of your login page, every visitor gets someone else's token and a stale session hint. The form then fails with 419.
Check the response headers of the login page for cf-cache-status: HIT, x-cache: Hit or an age header. Pages with forms should send Cache-Control: no-store or be excluded from the cache. Setting up a "cache everything" rule on a CDN is a common way to cause this, and it often starts right after someone turns on a performance setting.
The same applies to a page that stays open a long time. The default session lifetime is 120 minutes (SESSION_LIFETIME). A user who opens the login page, goes to lunch and then submits will see 419. You can add a friendly message instead of the raw error page. In bootstrap/app.php:
->withExceptions(function (Exceptions $exceptions) {
$exceptions->render(function (\Illuminate\Session\TokenMismatchException $e, $request) {
return redirect()->back()
->withInput($request->except('password'))
->with('error', 'Your session expired. Please try again.');
});
})
Step 7: Exclude Real Webhooks, Not Your Login
External services such as payment providers send POST requests with no session. Those return 419 unless you exclude them. Exclude only the webhook routes and verify the signature in your own code:
$middleware->validateCsrfTokens(except: [
'webhooks/*',
]);
Never exclude the login route to make 419 go away. That removes protection and hides the real fault. If you see 419 on a webhook route only, this step is the fix. If it is only on login, go back to Steps 2 to 6.
How Relia Helps
A 419 on login does not write a stack trace. Users see an error page, retry, and some of them leave. Relia watches the users, APIs, database and servers of a live product and joins related signals into one incident explained in plain words, including who was affected. That can show a jump in failed POST /login requests right after a deploy or config change. Laravel apps are detected by npx relia-sdk@latest init, and there is a Composer package for PHP and Laravel. You can also add uptime checks on key pages such as the login page. There is a Free plan, and a live demo at app.tryrelia.com/demo.
Related Guides
If your queue workers or sessions behave differently after a deploy, read Laravel Queue Jobs Not Processing in Production. For sign-in loops on other stacks, see Lovable Supabase Login Fails After Publish and NextAuth Session Null in Production.
FAQ
What does 419 Page Expired mean in Laravel?
Laravel could not match the CSRF token in the request to the one in the session. The token is missing, the session is gone, or the session cookie was not sent.
Why does Laravel 419 only happen in production?
Production adds HTTPS, secure cookies, proxies, several servers and caches. Any of these can lose the session. Local development uses one server over HTTP, so none of them apply.
Should I just disable CSRF protection to fix 419?
No. That opens your forms to cross-site request forgery. Find why the session is lost. Only exclude routes that are called by other servers, such as webhooks.
How do I stop 419 after a user leaves a page open?
Raise SESSION_LIFETIME if it fits your risk, refresh the token with a small request in the background, and show a clear "session expired, try again" message instead of the default error page.
Sources: Laravel CSRF docs, Laravel session docs, SaaSykit: 419 Page Expired error in Laravel, Laracasts thread on 419.