PHP

Learn how to set up Sentry in your PHP application.

  • You need a Sentry account and project
  • Your application needs to run on PHP 7.2 or later
  • Read one of these other guides if you use Laravel or Symfony

Select which Sentry features you'd like to install in addition to Error Monitoring to get the corresponding installation and configuration instructions below.

Install the Sentry SDK using Composer:

Copied
composer require sentry/sentry

To capture all errors, even the one during the startup of your application, you should initialize the Sentry PHP SDK as soon as possible.

Copied
\Sentry\init([
  'dsn' => 'https://examplePublicKey@o0.ingest.sentry.io/0',
]);

In PHP you can either capture a caught exception or capture the last error with captureLastError.

Copied
try {
  $this->functionFailsForSure();
} catch (\Throwable $exception) {
  \Sentry\captureException($exception);
}

If you're using Laravel's Forge platform to provision and deploy your PHP application, you can create a Sentry organization through Forge.

Sentry and Forge

Was this helpful?
Help improve this content
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").