Website Updated January 2023!

Websocket & Laravel Forge SSL Configuration




Weekly Programming Nugget

Recently, I ran into issues related to setting up a full Laravel Websockets connection using Laravel Forge.

I watched a few of the videos from around the web, yet I wasn't able to configure it myself. My biggest challenge was to set up Laravel Websockets in a way to configure a proxy server in the background, so I don't have to deal with the overhead cost of load balancing. In my situation, it was the easier and more affordable solution. So let's take a quick look at my solution, and compare some of the videos I've seen on the web.

I followed the following video example from Alex @codecourse.

To solve the SSL-related errors for Websockets here is my SSL configuration. Notice LARAVEL_WEBSOCKETS_SSL_LOCAL_CERT & LARAVEL_WEBSOCKETS_SSL_LOCAL_PK environment variables. Here you will add your socket server SSL certs, not your domain certs.

     * Define the optional SSL context for your WebSocket connections.
     * You can see all available options at:
    'ssl' => [
         * Path to local certificate file on filesystem. It must be a PEM encoded file which
         * contains your certificate and private key. It can optionally contain the
         * certificate chain of issuers. The private key also may be contained
         * in a separate file specified by local_pk.
        'local_cert' => env('LARAVEL_WEBSOCKETS_SSL_LOCAL_CERT', null),
         * Path to local private key file on filesystem in case of separate files for
         * certificate (local_cert) and private key.
        'local_pk' => env('LARAVEL_WEBSOCKETS_SSL_LOCAL_PK', null),
         * Passphrase for your local_cert file.
        'passphrase' => env('LARAVEL_WEBSOCKETS_SSL_PASSPHRASE', null),

        'verify_peer' => false