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 use Profiling, you'll also need to install the Excimer extension via PECL:

Copied
pecl install excimer

The Excimer PHP extension supports PHP 7.2 and up. Excimer requires Linux or macOS and doesn't support Windows. For additional ways to install Excimer, see docs.

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' ,
  // Specify a fixed sample rate
  'traces_sample_rate' => 1.0,
  // Set a sampling rate for profiling - this is relative to traces_sample_rate
  'profiles_sample_rate' => 1.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

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").