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

nestoracevedo's avatar

Laravel 6 - CSRF token mismatch in Docker

I basically have a problem with the token in a L6 app.

Currently the development site works fine on my machine. All forms work fine, I can login / logout and so on.

Now I have moved the site to a development machine where Docker is managed. The site opens, connects to the database, and displays the login form. The problem is that every time you try to log in, when you click the button, it immediately generates an error 419, where the error is CSRF token mismatch. I generate the hidden field where the token is inside the form with @csrf and the value matches the meta attribute of the page.

I have already cleared everything concerning the cache, but the problem persists. Has something similar happened to someone and have you been able to solve it?

0 likes
5 replies
geraintp's avatar

Its probably a time/zone issue in the docker vm if the times not correctly set your csrf tokens are expring immediately.

nestoracevedo's avatar

In my docker-compose I set the timezone and I get the same issue.

nestoracevedo's avatar

I explain: no matter the settings in the docker-compose file or laravel app config about timezone or file permissions, the token value in the hidden input is different from the session token value and it raises this error. I don't get why happens only in docker but in the develop and production servers (no dockenized) all work.

nestoracevedo's avatar

Good, one more time, I don't have a clue why, but finally it is working. I changed session_secure_cookie to false, and later to true and later again to false, runing config, cache and route clearing again and again and finally it worked.

sagar9637's avatar

I m trying like that but its not working. if any one know the solution just post it.

Please or to participate in this conversation.