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

Ligonsker's avatar

Can't get Laravel-Websockets to work over wss

Hello,

I have a website on example.com, and a WebSocket server on example-websocket-server.com.

Each have an SSL certificate so that I can access them from https://

I am using the websocket server as a websocket server for all the other websites, including example.com (there are more websites). However the wss:// connection fails (ws:// works).

The websocket server uses Laravel-Websocket as the server and it asks for a path to the PEM certificate: https://beyondco.de/docs/laravel-websockets/basic-usage/ssl#configuration:

'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' => '127.0.0.1',
        'port' => 6001,
        'scheme' => 'https',
        'curl_options' => [
            CURLOPT_SSL_VERIFYHOST => 0,
            CURLOPT_SSL_VERIFYPEER => 0,
        ]
    ],
],

and:

/*
 * 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.
 */

So for that PEM certificate I used the same certificate as the https:// certificate I am using on IIS

However I have a few issues - the certificate I am using on IIS was a .pfx file, with a given password string.

In order to create the PEM file used for the websocket server's wss connection, I first exported the .pfx to the PKCS7 file (.p7b), and then used OpenSSL to convert it to a .cer file. When I change the extension from .cer to .pem the file content look like that:

-----BEGIN PKCS7-----
[..long string..]
-----END PKCS7-----

(I tried using the file both as a .cer and .pem just in case)

But now the wss:// fails, and there is no debug information so I have no idea what is the cause. And in my case it can be multiple:

  1. I am using the wrong certificate
  2. The conversion I did from the .pfx to the .cer/.pem is wrong
  3. There is cross-origin restriction on my app side (Laravel) and that's the problem because the websockets server and the website are on different URLs
  4. Some configuration for WSS in IIS (Although normal ws:// connection worked)

Or something else? I just have no idea what to do because there is no debugging information

Thanks

0 likes
2 replies
LaryAI's avatar
Level 58

There could be multiple reasons why the wss:// connection is failing. Here are a few things you can try:

  1. Make sure that the certificate you are using is valid and trusted by the client. You can check this by opening the website in a browser and checking the SSL certificate information.

  2. Make sure that the certificate is in the correct format and contains the private key. You can use OpenSSL to convert the certificate to the correct format. Here's an example command:

    openssl pkcs12 -in certificate.pfx -out certificate.pem -nodes
    

    This will convert the certificate.pfx file to a certificate.pem file that contains the private key.

  3. Make sure that the WebSocket server is configured to use the correct certificate and key. You can check this by looking at the configuration file for the WebSocket server.

  4. Make sure that the WebSocket server is accessible from the client's network. You can check this by trying to connect to the WebSocket server from a different network or using a proxy.

  5. Make sure that there are no cross-origin restrictions in place that are preventing the WebSocket connection from being established. You can check this by looking at the network traffic in the browser's developer tools.

If none of these solutions work, you may need to consult the documentation for the WebSocket server or seek help from the developer community.

m_Faizan's avatar

@ligonsker I am facing the same issue. Was the issue resolved? If yes, can you tell me how you resolved it?

Please or to participate in this conversation.