Not every PHP app runs on Laravel or Symfony. Especially in older applications things go wrong silently: a warning in the error_log, a white page nobody reports. With the Sentry PHP SDK and errors.nl you see those errors right away, with the stack trace and the request.
1. Create a project
Create a free account at errors.nl (or log in), create an organization and a project and copy the DSN. It looks like https://<key>@ingest.errors.nl/<project>.
2. Install the SDK
composer require sentry/sentry
3. Start it as early as possible
Put this at the top of your front controller or bootstrap file, right after the autoloader:
require __DIR__ . '/vendor/autoload.php'; \Sentry\init([ 'dsn' => getenv('SENTRY_DSN'), 'environment' => 'production', 'release' => '[email protected]', 'error_types' => E_ALL & ~E_DEPRECATED & ~E_USER_DEPRECATED, ]);
The SDK registers its own exception and error handler. Fatals, uncaught exceptions and warnings now come in. With error_types you leave out deprecations, which would otherwise cost a lot of credits in older code.
4. Report an error yourself
Catching an exception but still want to see it? Then send it on yourself:
try { $payment->process(); } catch (\Throwable $e) { \Sentry\captureException($e); return showErrorPage(); }
5. Tags and user
With tags you search and filter later in the dashboard, for example by customer or by server:
\Sentry\configureScope(function (\Sentry\State\Scope $scope) { $scope->setTag('customer', 'smith-bakery'); $scope->setUser(['id' => $user->id]); });
Only pass an id for the user. Then you know how many people saw an error, without storing names or e-mail addresses.
6. No Composer?
If the app runs on a server where you can't use Composer, you can also send errors straight to our API with a single HTTP request. The example is shown with your project under Without SDK (HTTP).
Personal data
By default the SDK sends no IP addresses, cookies or request body. Leave send_default_pii at false unless you really need them.
On top of that, errors.nl filters passwords, tokens, e-mail addresses and account numbers from every error before we store it. Read more in Error monitoring and the GDPR.
Notifications
Want to know when something goes wrong without keeping the dashboard open? Turn on e-mail notifications for your project, or connect Slack, Teams, Discord or ntfy for push notifications on your phone.