Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

longestdrive's avatar

Configuring Pusher and Echo

I'm trying to set up and configure broadcasting in my Laravel app for the first time and having problems getting the config right. I've following the laracasts series on pusher & echo and think I've followed everything but encountering an error I can't quite decipher!

I've uncommented BroadcastServiceProvider in config/app.php I've updated by broadcasting.php config to:

'pusher' => [
            'driver' => 'pusher',
            'key' => env('PUSHER_APP_KEY'),
            'secret' => env('PUSHER_APP_SECRET'),
            'app_id' => env('PUSHER_APP_ID'),
            'options' => [
                'cluster' => env('PUSHER_APP_CLUSTER'),
                'host' => env('PUSHER_HOST') ?: 'api-' . env('PUSHER_APP_CLUSTER', 'mt1') . '.pusher.com',
                'port' => env('PUSHER_PORT', 443),
                'scheme' => env('PUSHER_SCHEME', 'https'),
                'encrypted' => true,
                'useTLS' => env('PUSHER_SCHEME', 'https') === 'https',
            ],
            'client_options' => [
                // Guzzle client options: https://docs.guzzlephp.org/en/stable/request-options.html
            ],
        ],

I've set the entries in .env:

#
PUSHER_APP_ID="XXXXXXX"
PUSHER_APP_KEY="XXXXXXX"
PUSHER_APP_SECRET="XXXXXXX"
PUSHER_APP_CLUSTER="eu"
PUSHER_PORT="443"
PUSHER_SCHEME="https"
PUSHER_HOST="ws-eu.pusher.com"
#
VITE_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
VITE_PUSHER_HOST="${PUSHER_HOST}"
VITE_PUSHER_PORT="${PUSHER_PORT}"
VITE_PUSHER_SCHEME="${PUSHER_SCHEME}"
VITE_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"

I've created a test event:

class ButtonClicked implements ShouldBroadcast
{
    use Dispatchable, InteractsWithSockets, SerializesModels;

    public $message;

    /**
     * Create a new event instance.
     */
    public function __construct($message)
    {
        $this->message = $message;

        ray("message", $this->message);
    }

    /**
     * Get the channels the event should broadcast on.
     *
     * @return array<int, \Illuminate\Broadcasting\Channel>
     */
    public function broadcastOn(): array
    {
        return [
            new Channel('my-channel-name'),
        ];
    }
}

and this is triggered from a controller:

    public function __invoke(Request $request): JsonResponse
    {
        ButtonClicked::dispatch('Hello world!');

        return response()->json(['success' => true]);
    }

Once I click the button that triggers the event I can see the event is fired and the queue works.

I can see from the logs and the failed jobs there's an error:

Illuminate\Broadcasting\BroadcastException: Pusher error: . in /var/www/html/vendor/laravel/framework/src/Illuminate/Broadcasting/Broadcasters/PusherBroadcaster.php:164
Stack trace:

Searches suggest my config is out but I can't see how I can resolve or exactly what the error is.

I can see from my browser console that pusher is active and from the pusher dashboard I can see the connection appears to be made but I don't get to see the event in the debug console.

I'm unsure where to start to resolve to get my config right.

For info I'm using Laravel 10

Any help appreciated

Thank you

0 likes
1 reply
LaryAI's avatar
LaryAI
AI
Best Answer
Level 58

To resolve the issue with configuring Pusher and Echo in your Laravel application, let's go through a checklist and some troubleshooting steps:

  1. Verify Pusher Credentials: Double-check that the PUSHER_APP_ID, PUSHER_APP_KEY, PUSHER_APP_SECRET, and PUSHER_APP_CLUSTER in your .env file are correct. These should match exactly with the credentials provided in your Pusher dashboard.

  2. Check Pusher Configuration: Ensure that your broadcasting.php configuration file is correctly set up. The configuration you provided looks mostly correct, but make sure there are no syntax errors. Here's a refined version:

    'pusher' => [
        'driver' => 'pusher',
        'key' => env('PUSHER_APP_KEY'),
        'secret' => env('PUSHER_APP_SECRET'),
        'app_id' => env('PUSHER_APP_ID'),
        'options' => [
            'cluster' => env('PUSHER_APP_CLUSTER'),
            'useTLS' => true,
        ],
    ],
    

    Note: The useTLS option is sufficient for enabling encryption, and you don't need to specify encrypted if useTLS is set to true.

  3. Clear Configuration Cache: After making changes to your .env file or configuration files, clear the configuration cache to ensure Laravel is using the latest settings:

    php artisan config:cache
    
  4. Check Event and Channel: Ensure that the event is correctly set up to broadcast on the intended channel. In your ButtonClicked event, you are broadcasting on my-channel-name. Make sure your frontend is listening to the same channel.

  5. Frontend Configuration: Ensure that your frontend is correctly set up to use Laravel Echo and Pusher. Here's a basic setup using Laravel Mix and Vue.js:

    import Echo from 'laravel-echo';
    window.Pusher = require('pusher-js');
    
    window.Echo = new Echo({
        broadcaster: 'pusher',
        key: process.env.MIX_PUSHER_APP_KEY,
        cluster: process.env.MIX_PUSHER_APP_CLUSTER,
        forceTLS: true
    });
    
    Echo.channel('my-channel-name')
        .listen('ButtonClicked', (e) => {
            console.log(e.message);
        });
    

    Ensure that the environment variables in your vite.config.js or webpack.mix.js are correctly set to use the VITE_ prefixed variables.

  6. Check Pusher Dashboard: Use the Pusher dashboard to verify if the events are being sent and received. This can help you determine if the issue is with the server-side broadcasting or the client-side listening.

  7. Network and Firewall: Ensure that your server can reach Pusher's servers. Sometimes, network restrictions or firewalls can block outgoing requests to Pusher.

  8. Debugging: If the issue persists, consider enabling debugging in Pusher to get more detailed error messages. You can do this by setting the logToConsole option in your Pusher client configuration:

    window.Pusher = require('pusher-js');
    
    window.Pusher.logToConsole = true;
    

By following these steps, you should be able to identify and resolve the configuration issues with Pusher and Echo in your Laravel application. If you continue to experience issues, consider checking the Laravel and Pusher documentation for any updates or changes that might affect your setup.

Please or to participate in this conversation.