note: The following instructions apply to Laravel 8.x and above. For instructions setting up Raygun on Laravel 5.x and below, see the legacy installation instructions further down the page.


The best way to install Raygun4PHP is to use the Composer CLI tool. Run the following command in your project folder to install it.

composer require mindscape/raygun4php

Paste the following code in your app/Exceptions/Handler.php file inside of the Handler class:

// Override the ExceptionHandler's report() function
public function report(Throwable $e)
  // Configure Raygun
  $httpClient = new Client([
      'base_uri' => '',
      'headers' => [
          'X-ApiKey' => 'paste_your_api_key_here'
  $transport = new GuzzleAsync($httpClient);
  $raygunClient = new RaygunClient($transport);

  $raygunClient->SendException($e); // Send exception to Raygun


  // Continue with the default Laravel error handling

This will send all unhandled PHP exceptions to Raygun. For more detailed configuration options of our Raygun4PHP provider, see our documentation here.

Note: Your app API key is provided for you in the set up instructions when you create a new application in your Raygun account, or can be viewed in the application settings.

Deploy Raygun into your production environment for best results, or raise a test exception. Once we detect your first error event, the Raygun app will automatically update.

Manually sending exceptions

The above instructions will set up the Raygun library to automatically detect and send all unhandled exceptions to the Raygun app. Sometimes, however, you may want to send exceptions manually, such as handled exceptions from within a try/catch block.

Here's an example of manually sending exceptions from a try/catch block:

  // Do something here that might go wrong
catch (\Exception $e) 
  // This will call the report function you overrode in the ExceptionHandler class

Legacy Laravel installation

Install the Raygun4PHP provider along side the laravel-raygun wrappers by using Composer. Installation instructions can be found at

Open the file app\Exceptions\Handler.php and add the following line before the class declaration.

use Raygun;

Inside app\Exceptions\Handler.php add following line into the report method.

public function report(Exception $e)
  // Send all unhandled exceptions:


The provider is open source and available at the Raygun4PHP repository.