0

I've a project setup that run beyondcode/laravel-websocket. It's configuration is setup so that it can run on local server and it does. Now i have uploaded project on cPanel. I can access the websocket dashboard from the server but i am not being able to connect. Can anyone help me providing step by step guide on setting up websocket on cPanel, like what changes I should do to: (My project is under public_html/projects/myproject)

broadcasting.php

'connections' => [

    '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' => false,
            'encrypted' => false,
            'host' => 'my_domain.com', //should be like this or 'my_domain.com/projects'  or should i leave it as 127.0.0.1
            'port' => 6001,
            'scheme' => 'http'
        ],
    ],

resources/view/js/bootstrap.js

window._ = require('lodash');

window.axios = require('axios');

window.axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest';

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: false,
    wsHost: window.location.hostname,
    wsPort: 6001,
    encrypted: false,
    enabledTransports: ['ws', 'wss']
});

And any other changes needed to any other file, any configuration. Just help me make it run.

  • I'd expect normally you have to follow all the steps here: https://beyondco.de/docs/laravel-websockets/basic-usage/starting . But in a shared hosting environment, you probably don't have sufficient access or priviliges for all of that. Always consider whether the environment you're intending to deploy to will support the code and architecture you need. – ADyson Mar 24 '23 at 13:33
  • Well that's what my question intends in some respect. How to make cPanel environment work for me in this case. I've terminal access and all. – Rashad Khan Mar 24 '23 at 14:03
  • well if you have terminal access, are you experiencing a specific problem when attempting to start the websocket server (or any other aspect of the process of either starting it up or keeping it running)? You mention being unable to connect. It's unclear a) what error you got, and b) whether that implies a firewall/network issue of some sort, or that the service simply isn't running. Clearly the solutions to those two things are very different. – ADyson Mar 24 '23 at 14:09
  • Sorry my bad, when i run php artisan websocket:serve, it just says server running on port 6001 and nothing else. When i goto websocket dashboard it doesn't it doesn't connect and says "Channels current state is unavailable". In console on dashboard, i get this "pusher.min.js:8 WebSocket connection to 'wss://mydomain.com:6001/app/my_key?protocol=7&client=js&version=4.3.1&flash=false' failed: WebSocket is closed before the connection is established.". I hope i'm being able to clarify. The problem is i can't find a guide to setup this on cPanel. – Rashad Khan Mar 24 '23 at 14:30
  • Thanks but you should [edit] your post with any/all important info about errors, status etc. It dosn't belong in the comments – ADyson Mar 24 '23 at 14:31
  • `it just says server running on port 6001 and nothing else`...does it say more, when you test it locally? – ADyson Mar 24 '23 at 14:31
  • Anyway you should probably contact the hosting provider and verify whether they support connections over non-standard ports, and whether they support long-running background processes. On a shared host, realistically they probably don't. Should have been a question to ask before purchasing the account, really. You may need your own dedicated server where you can do what you like, or a cloud-based solution, or perhaps you could use some sort of websockets-as-a-service cloud provider (assuming such exists) where you configure the socket but don't run the infrastructure. – ADyson Mar 24 '23 at 14:33

0 Answers0