A Laravel app that worked locally often breaks in production for configuration reasons rather than code bugs. This guide lists the common Laravel errors after deployment, with the fix for each, whether you host on cPanel or a VPS.
Before you start
- SSH or Terminal access to run
php artisanin the project folder. - Read
storage/logs/laravel.logfirst: it contains the real error behind a generic 500 page.
500 Server Error with no details
With APP_DEBUG=false Laravel shows a plain 500 page. Check, in order:
storage/logs/laravel.log(tail the last lines).- If that file is missing or not updated, Laravel cannot write logs: fix
storagepermissions (below). - The web server or PHP error log for errors before Laravel boots (PHP version, missing extensions).
No application encryption key has been specified
php artisan key:generateThis writes APP_KEY to .env. Generate it once per environment and keep it stable: changing it logs everyone out and makes encrypted data unreadable. If config is cached, run php artisan config:cache again afterwards.
The stream or file laravel.log could not be opened: Permission denied
PHP cannot write to storage or bootstrap/cache. On a VPS:
chown -R deploy:www-data storage bootstrap/cache && chmod -R ug+rwX storage bootstrap/cacheOn cPanel, files belong to your account user; make sure the folders are 755 and files 644, and that you did not upload them as another user.
419 Page Expired
A CSRF token or session problem on form posts:
- Forms must include
@csrf. SESSION_DOMAINandAPP_URLmust match the domain you visit (www vs non-www).- Over HTTPS, set
SESSION_SECURE_COOKIE=trueand configure trusted proxies so Laravel knows the request is HTTPS. - Sessions must be writable (
storage/framework/sessions) or use the database/Redis driver correctly.
Changes to .env have no effect
Configuration is cached. After editing .env:
php artisan config:clearOr rebuild the cache with php artisan config:cache. Note that env() calls outside config files return null when the config is cached; use config() in code.
Class not found / vendor/autoload.php missing
composer install --no-dev --optimize-autoloaderThe vendor folder is not in Git and must be installed on the server. After adding classes, composer dump-autoload refreshes the autoloader.
SQLSTATE connection errors
- [2002] Connection refused / No such file: wrong
DB_HOST; on cPanel uselocalhost, on a VPS try127.0.0.1. - [1045] Access denied: wrong user or password, or on cPanel the missing username prefix.
- [42S02] Base table not found: run
php artisan migrate --force.
404 on every route except the home page
URL rewriting is not working. On Apache/LiteSpeed, the public/.htaccess must be present and the document root must point to public. On Nginx, add try_files $uri $uri/ /index.php?$query_string;.
Mixed content or http links on an HTTPS site
Laravel thinks requests are HTTP because a proxy terminates SSL. Configure trusted proxies (in bootstrap/app.php on Laravel 11+, or the TrustProxies middleware on older versions), and set APP_URL=https://....
Vite manifest not found
Frontend assets were not built. Run npm ci && npm run build locally or on the server and deploy public/build.
Laravel errors FAQ
Can I turn on APP_DEBUG to see the error?
Only briefly on a non-public environment. Debug pages expose configuration and secrets.
Which artisan commands should run on each deploy?
migrate --force, optimize (or config/route/view cache), and restarting queue workers.
Do these fixes apply on cPanel?
Yes; the only differences are file ownership and pointing the document root to public.
