# PHP | Sentry for PHP

## [Prerequisites](https://docs.sentry.io/platforms/php.md#prerequisites)

* You need a [Sentry account](https://sentry.io/signup/) and project
* Your application needs to run on PHP 7.2 or later
* You need to be using Composer
* Read one of these other guides if you use [Laravel](https://docs.sentry.io/platforms/php/guides/laravel.md) or [Symfony](https://docs.sentry.io/platforms/php/guides/symfony.md)

## [Features](https://docs.sentry.io/platforms/php.md#features)

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

Error Monitoring\[ ]Logs\[ ]Tracing\[ ]Profiling

## [Install](https://docs.sentry.io/platforms/php.md#install)

Install the Sentry SDK using [Composer](https://getcomposer.org/):

```bash
composer require sentry/sentry
```

To use Profiling, you'll also need to install the Excimer extension via PECL:

```bash
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](https://docs.sentry.io/platforms/php/profiling.md#installation).

## [Configure](https://docs.sentry.io/platforms/php.md#configure)

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

```php
\Sentry\init([
  'dsn' => '___PUBLIC_DSN___',
  // Add request headers, cookies and IP address,
  // see https://docs.sentry.io/platforms/php/data-management/data-collected/ for more info
  'send_default_pii' => true,
  // ___PRODUCT_OPTION_START___ performance
  // Specify a fixed sample rate
  'traces_sample_rate' => 1.0,
  // ___PRODUCT_OPTION_END___ performance
  // ___PRODUCT_OPTION_START___ profiling
  // Set a sampling rate for profiling - this is relative to traces_sample_rate
  'profiles_sample_rate' => 1.0,
  // ___PRODUCT_OPTION_END___ profiling
  // ___PRODUCT_OPTION_START___ logs

  // Enable logs to be sent to Sentry
  'enable_logs' => true,
  // ___PRODUCT_OPTION_END___ logs
]);
```

In order to receive stack trace arguments in your errors, make sure to set `zend.exception_ignore_args: Off` in your php.ini

## [Verify](https://docs.sentry.io/platforms/php.md#verify)

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

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

## [Set up Sentry through Forge](https://docs.sentry.io/platforms/php.md#set-up-sentry-through-forge)

If you're using Laravel's Forge platform to provision and deploy your PHP application, you can create a Sentry organization through [Forge](https://forge.laravel.com/docs/integrations/sentry.html).

## Guides

- [laravel](https://docs.sentry.io/platforms/php/guides/laravel.md)
- [symfony](https://docs.sentry.io/platforms/php/guides/symfony.md)

## Pages in this section

- [configuration](https://docs.sentry.io/platforms/php/configuration.md)
- [crons](https://docs.sentry.io/platforms/php/crons.md)
- [data-management](https://docs.sentry.io/platforms/php/data-management.md)
- [enriching-events](https://docs.sentry.io/platforms/php/enriching-events.md)
- [feature-flags](https://docs.sentry.io/platforms/php/feature-flags.md)
- [integrations](https://docs.sentry.io/platforms/php/integrations.md)
- [legacy-sdk](https://docs.sentry.io/platforms/php/legacy-sdk.md)
- [logs](https://docs.sentry.io/platforms/php/logs.md)
- [metrics](https://docs.sentry.io/platforms/php/metrics.md)
- [profiling](https://docs.sentry.io/platforms/php/profiling.md)
- [security-policy-reporting](https://docs.sentry.io/platforms/php/security-policy-reporting.md)
- [tracing](https://docs.sentry.io/platforms/php/tracing.md)
- [troubleshooting](https://docs.sentry.io/platforms/php/troubleshooting.md)
- [usage](https://docs.sentry.io/platforms/php/usage.md)
- [user-feedback](https://docs.sentry.io/platforms/php/user-feedback.md)
