# Installation


Use the installation guide below to match your PHP version and initialization flow:

> This guide covers every supported setup. Follow only the steps that match your project: conditional instructions start with a bold "If ..." line describing when they apply. Steps without such a line always apply.
> Replace `YOUR-API-KEY` with the project's API key. You can find it in the project settings on https://flareapp.io.

## Step 1: Install the package using Composer

**If your project uses PHP 8.1 or newer:**

```shell
composer require spatie/flare-client-php:"^3.2"
```

**If your project uses PHP 8.0:**

```shell
composer require spatie/flare-client-php:"^1.0"
```

**If your project uses PHP 7.1, 7.2, 7.3, or 7.4:**

```shell
composer require facade/flare-client-php
```

## Step 2: Register Flare & configure

Add this code to your project (typically in your bootstrap or entry file):

**If your project uses PHP 8.1 or newer with logging and the Flare daemon:**

In `bootstrap.php`:

```php
require __DIR__ . '/vendor/autoload.php';

use Spatie\FlareClient\Flare;
use Spatie\FlareClient\FlareConfig;
use Spatie\FlareClient\Senders\DaemonSender;

$config = FlareConfig::make('YOUR-API-KEY')->useDefaults()->log()
    ->sendUsing(DaemonSender::class, ['daemon_url' => getenv('FLARE_DAEMON_URL') ?: 'http://127.0.0.1:8787']);

$flare = Flare::make($config)->start();

// Run your application

$flare->end();
```

**If your project uses PHP 8.1 or newer with logging, without the Flare daemon:**

In `bootstrap.php`:

```php
require __DIR__ . '/vendor/autoload.php';

use Spatie\FlareClient\Flare;
use Spatie\FlareClient\FlareConfig;

$config = FlareConfig::make('YOUR-API-KEY')->useDefaults()->log();

$flare = Flare::make($config)->start();

// Run your application

$flare->end();
```

**If your project uses PHP 8.1 or newer with the Flare daemon, without logging:**

In `bootstrap.php`:

```php
require __DIR__ . '/vendor/autoload.php';

use Spatie\FlareClient\Flare;
use Spatie\FlareClient\FlareConfig;
use Spatie\FlareClient\Senders\DaemonSender;

$config = FlareConfig::make('YOUR-API-KEY')->useDefaults()
    ->sendUsing(DaemonSender::class, ['daemon_url' => getenv('FLARE_DAEMON_URL') ?: 'http://127.0.0.1:8787']);

$flare = Flare::make($config)->start();

// Run your application

$flare->end();
```

**If your project uses PHP 8.1 or newer without logging or the Flare daemon:**

In `bootstrap.php`:

```php
require __DIR__ . '/vendor/autoload.php';

use Spatie\FlareClient\Flare;
use Spatie\FlareClient\FlareConfig;

$config = FlareConfig::make('YOUR-API-KEY')->useDefaults();

$flare = Flare::make($config)->start();

// Run your application

$flare->end();
```

**If your project uses PHP 8.1 or newer and you use the Flare daemon:**

The [Flare daemon](https://flareapp.io/docs/php/general/flare-daemon) forwards reports asynchronously so Flare delivery stays off your request path. See the [Flare daemon documentation](https://flareapp.io/docs/php/general/flare-daemon) for instructions on running the daemon on Kubernetes, Docker, or a generic VPS.

**If your project uses PHP 8.0:**

In `bootstrap.php`:

```php
require __DIR__ . '/vendor/autoload.php';

use Spatie\FlareClient\Flare;

$flare = Flare::make('YOUR-API-KEY')->registerFlareHandlers();
```

**If your project uses PHP 7.1, 7.2, 7.3, or 7.4:**

In `bootstrap.php`:

```php
require __DIR__ . '/vendor/autoload.php';

use Facade\FlareClient\Flare;

$flare = Flare::register('YOUR-API-KEY')->registerFlareHandlers();
```

## Step 3: Connect your project key

Your project key (`YOUR-API-KEY`) is already included in the initialization code from the previous step.

## Step 4: Verify your setup

Trigger a test exception to verify everything is working. This will terminate the script with an uncaught exception, but the exception should appear in Flare:

In `test.php`:

```php
throw new \Exception('This is an exception to test if the integration with Flare works.');
```

Great! From now on, Flare will track all errors and exceptions throughout your application.

In the next pages we will discuss the different configuration options available to you, methods you can call on the config object will always be using the `$config` variable, methods that should be called on the Flare object will be using the `$flare` variable.

### Using defaults

During these docs we'll often talk about features being enabled by default this is enabled by calling the `useDefaults` method on the Flare config instance. This method will enable a sensible set of features that should work for most applications. If you want to disable all default features, you can simply omit the `useDefaults` call and enable features manually.

### Setting the application root path

We recommend that you set the application root path. This will help Flare determine the correct file paths in your stack traces.

```php
$config->applicationPath('/path/to/your/application/root');
``` 

## Using an older PHP version?

The current `spatie/flare-client-php` package supports PHP 8.1 and later. If you're on PHP 8.0 or below, older clients are available.

In the past we've had multiple clients for framework agnostic PHP applications without support for performance monitoring. While these packages are still available, we recommend using the new flare-client-php package for all new projects:

- [spatie/flare-client-php v2](/docs/php/older-packages/flare-client-php-v2): supports PHP 8.2 and later
- [spatie/flare-client-php v1](/docs/php/older-packages/flare-client-php-v1): supports PHP 8.0 and later
- [facade/flare-client-php v1](https://github.com/facade/flare-client-php): supports PHP 7.1 until 8.0

## Using Ignition?

If you're maintaining an older project that already uses Ignition, you can keep that setup in place while you work on the app.

For older projects where you still need to add Flare, we recommend installing the standalone `spatie/flare-client-php` or `facade/flare-client-php` package directly instead of adding Ignition.

## Upgrading

You can find more information about the `flare-client-php` upgrade from v1 to v2 [here](https://github.com/spatie/flare-client-php/blob/main/UPGRADING.md).
