Most Laravel health check endpoints lie. They return 200 OK no matter what is happening underneath, because all they do is prove PHP can answer a request. Your database can be down, Redis unreachable, and the disk full, and the endpoint still says everything is fine. A load balancer that trusts that answer keeps sending traffic to a broken app. This post shows how to build a Laravel health check endpoint that tells the truth, using checks I run in production apps: a database probe, a Redis probe, a queue check, and a disk check, with a real 503 when any of them fail.
Liveness versus readiness: two different questions
Before writing the endpoint, decide what it answers. Liveness asks whether the process is alive. Readiness asks whether the app can serve real work right now. A route that only returns a string answers liveness, which is fine for a Kubernetes liveness probe, but a load balancer health check needs readiness: it has to know whether this instance should receive traffic. One endpoint can serve both purposes if it checks the dependencies the app needs to do its job, and returns 200 only when all of them respond. Keep the endpoint public and unauthenticated, but keep it outside your auth and throttle middleware groups so a monitoring probe never gets a 401 or a 429.
Check the database with a real query
Opening a connection is not enough. A connection can open and still fail on the first real query if the database is in recovery or the user lost its grants. Run a query that actually touches the server:
<?php
use Illuminate\Support\Facades\DB;
try {
DB::connection()->getPdo();
DB::select('select 1');
$checks['database'] = 'ok';
} catch (\Throwable $e) {
$checks['database'] = 'fail';
$ok = false;
}
The select 1 is cheap and proves the round trip works. Log the exception message for yourself, but never put it in the response. A health endpoint that leaks a database error string hands an attacker your driver, your host, and sometimes your credentials path. Keep the public response to status words only.
Check Redis and the queue connection
If your app uses Redis for cache and queues, a dead Redis means your app is half broken even while the database is fine. Ping it directly instead of trusting the cache driver config:
<?php
use Illuminate\Support\Facades\Redis;
try {
$pong = Redis::connection()->ping();
$checks['redis'] = $pong === 'PONG' ? 'ok' : 'fail';
$ok = $ok && $checks['redis'] === 'ok';
} catch (\Throwable $e) {
$checks['redis'] = 'fail';
$ok = false;
}
For the queue, the honest check is whether jobs can be pushed. The database queue driver is already covered by the database check, and Redis queues by the ping above. Optionally, also report the failed jobs count as information for your alerting, not as a pass or fail: a few failed jobs are normal in a busy app, a spike is not.
Check disk space before the disk fills
A full disk kills an app in slow, confusing ways. Sessions stop writing, uploads fail, logs stop, and queues back up, while every HTTP response still looks normal. A one-line check catches it early:
<?php
$freeBytes = disk_free_space(storage_path());
$minBytes = 100 * 1024 * 1024; // 100 MB
$checks['disk'] = $freeBytes !== false && $freeBytes > $minBytes
? 'ok'
: 'fail';
$ok = $ok && $checks['disk'] === 'ok';
One hundred megabytes is a reasonable floor for a typical Laravel app, but pick a number that fits your server. The point is to fail loudly when you cross it, instead of learning the disk is full from a user reporting failed uploads.
Return 503 when anything fails
The status code is the whole point. A health check that returns 200 with a body saying "database: fail" is still a lie to every load balancer, uptime monitor, and Kubernetes probe that reads the code and ignores the body. Return 200 only when every check passes, and 503 the moment one fails:
<?php
use Illuminate\Support\Facades\Route;
Route::get('/health', function () {
$checks = [];
$ok = true;
// Database, Redis, and disk checks go here,
// each one setting $checks[...] and $ok = false on failure.
return response()->json([
'status' => $ok ? 'ok' : 'degraded',
'checks' => $checks,
], $ok ? 200 : 503);
});
Put the route in routes/web.php so it stays available even if your API routes change, and test it the way a load balancer would: run curl -i https://your-app.example/health and read the status line. Then stop the database, run it again, and confirm you get a 503. If you cannot flip a dependency off in staging, point the app at a wrong database host in a test environment. A health check you have never seen fail is a health check you have never tested.
Keep the endpoint fast and out of the way
A health check runs constantly. A load balancer can hit it every few seconds on every target, so keep it light. Each check above is a single round trip or function call, and the whole endpoint should answer in well under a second. Do not add slow checks like external API calls or full table counts. If a check takes more than a second, give it a short timeout or move it to a scheduled monitoring job. Also cache nothing about the result: a cached "ok" from five minutes ago is the same lie you started with. Expect noisy probe traffic in the access logs for the first day. That is normal, and it beats finding out your monitoring was blind during the next outage.
The takeaway
A Laravel health check endpoint earns its keep only when it can say no. Check the database with a real query, ping Redis, confirm there is disk space, and return 503 the moment any of them fail. Keep the response free of error details, keep the checks fast, and prove the endpoint fails by breaking a dependency on purpose in staging. Once it is honest, it is a real input to incident response instead of a green light that never turns red. For what to do when that 503 actually shows up, see How I Triage a Production Incident.