---
title: "Show all PHP errors and catch the ones visitors never see"
description: "PHP errors go to the page or to the error log, and php.ini decides which. With the production php.ini, 4 of our 5 errors gave the visitor an empty 500 page, and only the error log kept them."
canonical: "https://logbrew.co/en/errors/php"
last_updated: "2026-11-25"
---

# Show all PHP errors and catch the ones visitors never see

PHP errors go to the page or to the error log, and php.ini decides which. With the production php.ini, 4 of our 5 errors gave the visitor an empty 500 page, and only the error log kept them.

In development, set `display_errors` to `On` and `error_reporting` to `E_ALL`. In production, keep errors off the page and read the error log.

Tested on November 25, 2026 with PHP 8.5.6, logbrew/sdk 0.1.26, Composer 2.10.0, and logbrew CLI 0.1.96

Canonical: https://logbrew.co/en/errors/php

## Which PHP errors reached LogBrew

| PHP error | `set_exception_handler` alone | All 3 handlers |
| --- | --- | --- |
| Warning, undefined variable | No | Log |
| Uncaught `RuntimeException` | Issue | Issue |
| Undefined function | Issue | Issue |
| Memory limit | No | Issue |
| Parse error | No | Issue |

5 errors in PHP 8.5.6 with the production php.ini, sent by logbrew/sdk 0.1.26 to a local LogBrew API.

## Show every error in development

### Show errors at the top of the script

With the production php.ini, `display_errors` is `Off`. Our page with an undefined variable printed an empty value and no warning. These 3 lines at the top of the file showed the warning on the page.

```bash
ini_set('display_errors', '1');
ini_set('display_startup_errors', '1');
error_reporting(E_ALL);
```

Output

```text
<br />
<b>Warning</b>:  Undefined variable $discount in <b>…/shop/public/cart.php</b> on line <b>7</b><br />
Items: 3, discount: 
cart page finished
```

### Set them in php.ini to see parse errors

PHP runs `ini_set()` only after it parses the file. A missing `;` in the same file still gave a blank 500 page. Put the same values in php.ini, then restart PHP-FPM or your web server.

```bash
display_errors = On
display_startup_errors = On
error_reporting = E_ALL
```

Output

```text
<br />
<b>Parse error</b>:  syntax error, unexpected token &quot;echo&quot; in <b>…/shop/public/invoice.php</b> on line <b>3</b><br />
```

### Find the php.ini that PHP loads

The command line and the web server can load different files. `php --ini` shows the file of the command line. For the web server, print `php_ini_loaded_file()` from a page.

```bash
php --ini
```

Output

```text
Configuration File (php.ini) Path: "/opt/homebrew/etc/php/8.5"
Loaded Configuration File:         "/opt/homebrew/etc/php/8.5/php.ini"
Scan for additional .ini files in: "/opt/homebrew/etc/php/8.5/conf.d"
Additional .ini files parsed:      (none)
```

## Log errors in production

### Hide errors from visitors and log them

Keep `display_errors` `Off`, so a visitor never sees a file path or a query. Turn on `log_errors` and give `error_log` a file that PHP can write.

```bash
display_errors = Off
log_errors = On
error_log = /var/log/php/error.log
```

### Read the error log

Each blank 500 page left its error in the log. PHP 8.5 also writes a stack trace for a fatal error such as the memory limit.

```bash
tail -n 20 /var/log/php/error.log
```

Output

```text
[25-Nov-2026 09:11:29 UTC] PHP Warning:  Undefined variable $discount in …/shop/public/cart.php on line 3
[25-Nov-2026 09:11:29 UTC] PHP Fatal error:  Uncaught RuntimeException: Payment API timed out in …/shop/public/checkout.php:3
Stack trace:
#0 {main}
  thrown in …/shop/public/checkout.php on line 3
[25-Nov-2026 09:11:29 UTC] PHP Fatal error:  Uncaught Error: Call to undefined function send_receipt() in …/shop/public/receipt.php:2
Stack trace:
#0 {main}
  thrown in …/shop/public/receipt.php on line 2
[25-Nov-2026 09:11:29 UTC] PHP Fatal error:  Allowed memory size of 134217728 bytes exhausted (tried to allocate 153000032 bytes) in …/shop/public/export.php on line 2
Stack trace:
#0 …/shop/public/export.php(2): str_repeat()
#1 {main}
[25-Nov-2026 09:11:29 UTC] PHP Parse error:  syntax error, unexpected token "echo" in …/shop/public/invoice.php on line 3
```

## Send every error to LogBrew

### Install the LogBrew PHP SDK

The SDK needs PHP 8.2 or later.

```bash
composer require logbrew/sdk
```

### Add 3 handlers in 1 file

`set_exception_handler` gets uncaught exceptions and `Error`s, but not a fatal error such as the memory limit. `register_shutdown_function` reads that error from `error_get_last()` after PHP stops the script. `set_error_handler` sends each warning as a log. Set `LOGBREW_INGEST_KEY` to a `server` key of your project.

```bash
<?php
require __DIR__ . '/vendor/autoload.php';

use LogBrew\HttpTransport;
use LogBrew\IssueDiagnostics;
use LogBrew\LogBrewClient;
use LogBrew\SdkError;

$logbrew = LogBrewClient::create((string) getenv('LOGBREW_INGEST_KEY'), 'shop', '1.0.0');
$id = static fn (): string => 'evt_' . bin2hex(random_bytes(8));
$now = static fn (): string => gmdate('Y-m-d\TH:i:s\Z');

set_error_handler(static function (int $type, string $message) use ($logbrew, $id, $now): bool {
    $logbrew->log($id(), $now(), ['message' => $message, 'level' => 'warning', 'logger' => 'php']);
    return false;
});

set_exception_handler(static function (Throwable $error) use ($logbrew, $id, $now): void {
    error_log('PHP Fatal error:  Uncaught ' . $error);
    http_response_code(500);
    $logbrew->issue($id(), $now(), IssueDiagnostics::fromThrowable($error, mechanismType: 'php.uncaught', handled: false));
});

register_shutdown_function(static function () use ($logbrew, $id, $now): void {
    $error = error_get_last();
    if ($error !== null && in_array($error['type'], [E_ERROR, E_PARSE, E_CORE_ERROR, E_COMPILE_ERROR], true)) {
        $logbrew->issue($id(), $now(), ['title' => 'PHP Fatal error', 'level' => 'fatal', 'message' => $error['message']]);
    }
    try {
        $logbrew->shutdown(new HttpTransport());
    } catch (SdkError $failure) {
        error_log('LogBrew: ' . $failure->getMessage());
    }
});
```

### Load the file before every script

Set `auto_prepend_file` in php.ini, or `require` the file first in your front controller.

```bash
auto_prepend_file = /var/www/shop/logbrew.php
```

### Keep the log line and the 500 status

With an exception handler, PHP no longer writes `PHP Fatal error:  Uncaught` to the log. Without the 2 lines below, our checkout page also answered `200` with an empty page. With them, the log line and the `500` came back.

```bash
error_log('PHP Fatal error:  Uncaught ' . $error);
http_response_code(500);
```

Output

```text
HTTP/1.1 500 Internal Server Error
[25-Nov-2026 09:18:11 UTC] PHP Fatal error:  Uncaught RuntimeException: Payment API timed out in …/shop/public/checkout.php:3
Stack trace:
#0 {main}
```

### Read the errors with the LogBrew CLI

Each exception and fatal error is 1 issue, and each warning is 1 log.

```bash
logbrew read issues --project "<project_id>" --since 1h
logbrew read logs --project "<project_id>" --since 1h
```

Output

```text
Issues (4)
- 2dfc15b0-33bc-5fae-ba66-3defb0871e39 unresolved error priority=medium Error in receipt.php:2 occurrences=1 users=unknown last_seen=2026-11-25T09:18:11Z service=unknown_service trace=3deaceb311395198c2bd5a33389ef2e3 assignee=unassigned [unversioned / production]
- 1a4b7e84-6dc3-5f23-a861-1c9e2c03f55e unresolved error priority=medium RuntimeException occurrences=1 users=unknown last_seen=2026-11-25T09:18:11Z service=unknown_service trace=dde520aa061f3ad867b0b55ceb5c13aa assignee=unassigned [unversioned / production]
- 4de1364d-e748-5dfe-9be8-80bd8ede83aa unresolved critical priority=high PHP Fatal error occurrences=1 users=unknown last_seen=2026-11-25T09:18:11Z service=unknown_service trace=e82dfd4169caebdff0414cdfafd53314 assignee=unassigned [unversioned / production]
- d8192abc-8c98-54e5-9b95-424c89593aeb unresolved critical priority=high PHP Fatal error occurrences=1 users=unknown last_seen=2026-11-25T09:18:11Z service=unknown_service trace=3424e320bf52d61aa14204424f3ae127 assignee=unassigned [unversioned / production]
Logs (1)
- warning Undefined variable $discount service=unknown_service trace=18ac51390e834d7c3cfd36ab4cb8f48a [unversioned / production]
```

## What we saw when we tested it

We ran PHP 8.5.6 on macOS 27.2 with the built-in web server and the `php.ini-production` file that PHP ships. 5 pages each had 1 error, and curl 8.7.1 requested each page once.

Only the warning page answered `200`. The other 4 answered `500` with 0 bytes, and the error log kept a line for all 5. With `display_errors` `On`, PHP put each error on the page and answered `200`, even for the fatal errors.

|  | HTTP | PHP error log |
| --- | --- | --- |
| A warning | `200` | `PHP Warning` |
| An uncaught exception | `500` | `PHP Fatal error` |
| An undefined function | `500` | `PHP Fatal error` |
| The memory limit | `500` | `PHP Fatal error` |
| A parse error | `500` | `PHP Parse error` |

## Why set_exception_handler misses fatal errors

Since PHP 7, most errors are `Error` exceptions, such as a call to an undefined function, and `set_exception_handler` gets them. A few errors still stop the script at once, such as the memory limit and a parse error in the requested file. No handler gets those.

PHP still runs the shutdown functions after it stops the script. `error_get_last()` then returns the error with its type, message, file, and line.

1. PHP stops the script
2. PHP runs the shutdown functions
3. error_get_last() returns the error

## What LogBrew records

LogBrew kept each uncaught exception as 1 issue with its type, `php.uncaught` as its mechanism, and its stack frames with the file name only, such as `checkout.php` line 3. The SDK leaves out the exception message by default, because a message can hold user data. Pass `message:` to `fromThrowable()` when your messages are safe.

The shutdown function sent the memory limit and the parse error as issues with the level `critical` and the PHP message. The dashboard, the CLI, and the MCP server read them like any other LogBrew issue.

- `RuntimeException`
  - `level`: `error`
  - `exception.type`: `RuntimeException`
  - `mechanism`: `php.uncaught`
  - `handled`: `false`
  - Stack frames: 1
  - `messageState`: `redacted`
- `PHP Fatal error`
  - `level`: `critical`
  - Message: `Allowed memory size of 134217728 bytes exhausted …`

## Questions people ask

### How do I show all errors in PHP?

Set `display_errors = On`, `display_startup_errors = On`, and `error_reporting = E_ALL` in php.ini, then restart PHP. `ini_set()` at the top of a script works too, but not for a parse error in that file.

### Why does my PHP page show a blank white page?

A fatal error stopped the script, and `display_errors` is `Off`, so PHP sent an empty 500 page. The error is in the PHP error log.

### Where is the PHP error log?

It is the file in the `error_log` setting. With no value, PHP sends errors to the web server's error log, or to stderr on the command line.

### Can set_exception_handler catch fatal errors?

It gets `Error` exceptions, such as a call to an undefined function. It does not get the memory limit or a parse error. Use `register_shutdown_function` with `error_get_last()` for those.

### What is the difference between a PHP warning and a fatal error?

After a warning, PHP runs the rest of the script. After a fatal error, PHP stops it. Our warning page answered `200`, and each fatal error answered `500`.

## Track every PHP error in 1 place

Send PHP exceptions, fatal errors, and warnings to LogBrew with the PHP SDK, and read them from the dashboard, the CLI, or your AI agent. Start on the generous free tier, no card needed.

[Start Free](https://logbrew.co/en)

## Sources

- [PHP manual, Errors and Logging Configuration](https://www.php.net/manual/en/errorfunc.configuration.php)
- [php/php-src, php.ini-production (PHP-8.5)](https://github.com/php/php-src/blob/PHP-8.5/php.ini-production)
- [PHP manual, Error](https://www.php.net/manual/en/class.error.php)
- [PHP manual, set_exception_handler](https://www.php.net/manual/en/function.set-exception-handler.php)
- [PHP manual, register_shutdown_function](https://www.php.net/manual/en/function.register-shutdown-function.php)
- [PHP manual, error_get_last](https://www.php.net/manual/en/function.error-get-last.php)
- [LogBrewCo/sdk, php/logbrew-php](https://github.com/LogBrewCo/sdk/tree/main/php/logbrew-php)

## Fix an error

- [Fix the script error that hides its message, file, and line](https://logbrew.co/en/errors/script-error)
- [Fix the Failed to fetch error and tell its 3 causes apart](https://logbrew.co/en/errors/failed-to-fetch)
- [Fix java.lang.NullPointerException in Kotlin and Android from its message](https://logbrew.co/en/errors/nullpointerexception)
- [Fix Minified React error #418 and #185 from the full message and your source line](https://logbrew.co/en/errors/minified-react-error)
- [Fix SyntaxError Cannot use import statement outside a module in the browser and in Node.js](https://logbrew.co/en/errors/cannot-use-import-statement-outside-a-module)
- [Fix AxiosError Network Error and find which of its 3 causes you have](https://logbrew.co/en/errors/axios-network-error)
- [Fix the HTTP 499 error and find out who stopped waiting](https://logbrew.co/en/errors/http-499)
- [Fix 413 Request Entity Too Large and find which layer refused it](https://logbrew.co/en/errors/http-413)
- [Fix nginx 504 Gateway Time-out and find which timeout fired](https://logbrew.co/en/errors/http-504)
- [JavaScript errors and JVM exceptions we reproduced, and how to fix each one](https://logbrew.co/en/errors)
