Laravel and PHP errors, explained
The Laravel and PHP errors developers hit most, each with its real causes, how to tell which one you have, the fix in code and how to catch it.
Each page starts with the exact message as Laravel or PHP prints it, lists the causes from most to least common, and shows how to confirm and fix each one. The code runs on Laravel 12 and 13 with PHP 8.3 or later; where the two Laravel versions differ, the page says so.
Every page ends with how to notice the error in production before a user reports it. To see all of your app's exceptions in one list, grouped and counted, see issues.
- 419 Page Expired and CSRF token mismatch in Laravel: Laravel returns 419 Page Expired, or "CSRF token mismatch." as JSON, when a POST has no valid CSRF token: no @csrf, an expired session or a cookie issue.
- Allowed memory size of 134217728 bytes exhausted: PHP hit memory_limit. In Laravel it is usually a query loading too many models, a missing eager load or a growing queue worker. How to find and fix it.
- NET::ERR_CERT_DATE_INVALID: causes and fixes: Chrome shows NET::ERR_CERT_DATE_INVALID when the certificate expired or the visitor's clock is wrong. How to tell which, renew it and get warned in time.
- MySQL server has gone away (error 2006) in Laravel: MySQL closed the connection: an idle queue worker passed wait_timeout, a query hit max_allowed_packet or the server restarted. Fixes for Laravel.
- No application encryption key has been specified: Laravel throws this when APP_KEY is empty in the config it loaded: no .env, a config cache built without the key, or a container that never got it.
- SQLSTATE[HY000] [2002] Connection refused in Laravel: Laravel can't reach MySQL. "Connection refused" is a wrong host or port or a stopped server; "No such file or directory" is DB_HOST=localhost using a socket.
- SQLSTATE errors in Laravel, code by code: What SQLSTATE HY000 2002, 1045, 42000, 23000, 42S02 and 42S22 mean in a Laravel QueryException, how to tell which cause you have, and the fix for each.