Laravel Preview 500 Error: 5 Fixes, In Order
The build succeeded. The preview URL is in the pull request comment. You open it and get a 500 with no useful body, because APP_DEBUG is off and the error page is deliberately blank. There is nothing in the browser to work with.
Laravel previews fail earlier than most stacks. Rails and Phoenix at least boot and serve a page before something breaks. Laravel refuses to start, or starts and then throws on the first request that touches the framework. Five causes account for nearly all of it, and they're worth checking in this order — each one masks the next.
1. APP_KEY is missing, and Laravel will not start without it
Laravel throws MissingAppKeyException — "No application encryption key has been specified" — when APP_KEY is absent or empty. Your .env is gitignored, .env.example ships with APP_KEY= blank, so a fresh container has no key at all.
Generate one and put it in the project's environment variables:
php artisan key:generate --show
# base64:9kQ2... (paste this whole string, including the base64: prefix)
Two things trip people up. The base64: prefix is part of the value — a key without it is rejected. And for previews, generate a dedicated key rather than reusing production. A preview key that leaks compromises preview sessions, not real ones. The Laravel framework page lists APP_KEY first among the required variables for exactly this reason.
2. A stale config cache is overriding the variable you just set
You added APP_KEY, redeployed, and got the same error. That's usually not a wrong value — it's bootstrap/cache/config.php.
php artisan config:cache flattens every config value into a single PHP file. From then on, env() calls inside config/*.php return whatever was cached, and changes to environment variables have no effect until the cache is rebuilt. If your build step runs config:cache before the runtime environment exists, the cached file contains the build-time values — which for a preview means nulls.
The fix is ordering. Cache config at boot, not at build:
php artisan config:clear && php artisan config:cache
If you'd rather not think about it, don't cache config in previews at all. The performance difference on a preview container that three people are looking at is not measurable. Caching is a production optimisation.
There's a known quirk worth knowing: on the first config:cache run in a fresh environment, APP_KEY can come back missing and appear only on the second run (laravel/framework#38242). If the key is definitely set and still not found, run the cache command twice before you go looking for a deeper cause.
3. The Vite manifest doesn't exist, so every asset 404s
Laravel 9+ ships Vite. @vite('resources/js/app.js') reads public/build/manifest.json to resolve hashed asset filenames. If that file isn't there, you get:
Vite manifest not found at: /app/public/build/manifest.json
public/build is in Laravel's default .gitignore, so a Git-based build never has it unless the build step produces it. Run the front-end build as part of the build command:
composer install --no-dev --optimize-autoloader
npm ci && npm run build
Two related traps. A leftover public/hot file — created by npm run dev on someone's laptop and accidentally committed — makes Laravel look for a dev server that doesn't exist, and every asset fails even though the manifest is present. Delete it. And if you set build.manifest: true in vite.config.js, Vite writes .vite/manifest.json instead, which Laravel doesn't look for. Leave the filename alone.
4. The proxy isn't trusted, so Laravel thinks it's serving HTTP
Preview traffic terminates TLS at the router and reaches your container over plain HTTP. Laravel builds URLs from the request it receives, so without configuration it generates http:// links on an https:// page. Browsers block the mixed content, and redirect()->secure() loops.
Tell Laravel to trust the proxy. In Laravel 11 the middleware is configured in bootstrap/app.php:
->withMiddleware(function (Middleware $middleware) {
$middleware->trustProxies(at: '*', headers: Request::HEADER_X_FORWARDED_FOR |
Request::HEADER_X_FORWARDED_HOST |
Request::HEADER_X_FORWARDED_PORT |
Request::HEADER_X_FORWARDED_PROTO);
})
at: '*' trusts every proxy, which is correct inside a container that only the router can reach. On a host with a public interface, list the proxy addresses instead.
The symptom to recognise: assets load fine but form submissions return 419 "Page Expired". That's CSRF failing because the session cookie was issued over one scheme and submitted over another. It looks like a session bug and it's a proxy bug.
5. The database isn't there, and migrations run against nothing
A preview runs your application container. It does not come with a database attached, and no per-preview database is provisioned for you. DATABASE_URL points at something you control.
On the Laravel framework page the reference start command is:
php artisan migrate --force && php artisan serve --host=0.0.0.0 --port=${PORT:-8000}
That's fine against a disposable database. Against a shared development database that three branches are pointed at, an automatic migrate on every preview boot is how two branches fight over the same schema mid-review. Decide deliberately: disposable database and migrate on boot, or shared database and migrate by hand.
--force is required. Without it, migrate prompts for confirmation in a non-interactive environment and the container hangs until it times out.
The check that actually tells you it works
Don't stop at "the page loads." A Laravel preview can serve a styled page and still be broken — the session driver, the queue, and every authenticated route depend on config that a static page never touches.
Open the preview and do three things: submit a form (tests CSRF and sessions), log in (tests the session driver and APP_KEY), and load a page that queries the database. If all three work, the five settings above are correct. If the page loads and the form 419s, go back to check 4. If the page loads and the query 500s, go back to check 5.
Getting the URL in the first place
None of this needs a pipeline file. PreviewDrop reads your composer.json, detects Laravel, and builds the project. You can override the install, build, and start commands in Project Settings when your layout needs something specific — a front-end build step, a custom PHP extension, a queue worker.
The loop is short: connect the repo, paste APP_KEY, APP_ENV, APP_URL and DATABASE_URL into the project's environment variables, then open a pull request. A comment lands on the PR with the URL. Push again and the same URL updates in place. Close or merge the PR and the preview is torn down. If a build can't start the container, the deployment is marked failed with the reason shown in the dashboard rather than sitting in queued and holding one of your concurrent-preview slots.
Start with the pull request that's been waiting longest. The quickstart docs walk through the full setup, or sign up and put a live URL on your next branch. The Free plan covers two concurrent previews across three projects with a 24-hour preview lifetime and 256MB per container — enough to prove the loop on a real branch. Paid plans start at $19/mo for the workspace, not per seat.
Want previews on your own pull requests? Start free — 2 concurrent previews, no credit card.