PHP

On this page, we get you up and running with Sentry's PHP SDK, automatically reporting errors and exceptions in your application.

Using a framework? Take a look at our specific guides to get started.

Related Guides

This Sentry PHP SDK provides support for PHP 7.2 or later. If you are using our previous PHP SDK, you can access the legacy SDK documentation, until further notice.

Sentry captures data by using an SDK within your application’s runtime. These are platform-specific and allow Sentry to have a deep understanding of how your application works.

Install the SDK using Composer.

Copied
composer require sentry/sentry

After you’ve completed setting up a project in Sentry, Sentry will give you a value which we call a DSN or Data Source Name. It looks a lot like a standard URL, but it’s just a representation of the configuration required by the Sentry SDKs. It consists of a few pieces, including the protocol, public key, the server address, and the project identifier.

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' ]);

Copied
try {
    $this->functionFailsForSure();
} catch (\Throwable $exception) {
    \Sentry\captureException($exception);
}
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").