Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open up port 6001 for laravel-websockets (php via cli service) #12

Open
eminos opened this issue Nov 18, 2020 · 6 comments
Open

Open up port 6001 for laravel-websockets (php via cli service) #12

eminos opened this issue Nov 18, 2020 · 6 comments

Comments

@eminos
Copy link

eminos commented Nov 18, 2020

I'm trying to figure out how to run laravel-websockets with lando.
https://beyondco.de/docs/laravel-websockets/getting-started/introduction
laravel-websockets is a PHP CLI Ratchet application running on port 6001.

This is my lando file:

name: lintex
recipe: laravel
config:
  webroot: public
  php: '7.4'
  composer_version: '2.0.4'
  via: nginx
  database: mysql:8.0
  cache: redis
excludes:
  - vendor
  - node_modules
proxy:
  appserver_nginx:
    - lintex.local
    - "*.lintex.local"
  websockets:
    - lintex.local:6001
services:
  database:
    type: mysql:8.0
    portforward: 3306
    creds:
      user: lintex
      password: lintex
      database: lintex
  horizon:
    type: php:7.4
    via: cli
    command: php /app/artisan horizon
  websockets:
    type: php:7.4
    via: cli
    portforward: 6001
    ports:
      - '6001'
    command: php /app/artisan websockets:serve
bindAddress: "0.0.0.0"

It seems the port 6001 is not accessible from the host.
The websockets service also needs to be accessable from the other services.

@dustinleblanc
Copy link

dustinleblanc commented Nov 18, 2020

@eminos the way the proxy works, it is proxying port 6001 inside the container to ports 80/443 (or whatever ports you have the proxy bound to) on the host, so what you really want to do is bind it to a DIFFERENT domain than the nginx appserver, like ws-lintext.local or ws.lintex.local etc.

This definitely isn't intuitive when the standard way to run stuff is localhost:newport but its how things work with our proxy.

You can find me in the Lando slack or the Laravel Discord if you have more questions!

@eminos
Copy link
Author

eminos commented Nov 18, 2020

Thank you @dustinleblanc ! I do have some more questions. I wrote to you on the Laravel Discord. (Couldn't get access to Lando Slack.)

@dustinleblanc
Copy link

Hey @eminos! I don't see the question, just made sure to login, my username over there is dustin#0971. I might have signed up with a couple of accounts over time as discord is weird with accounts/emails, but you can hit me there!

@eminos
Copy link
Author

eminos commented Nov 18, 2020

After a long chat with Dustin he helped me figure it all out! Thanks Dustin!

So for anyone wondering or having the same issue...
The key seems to be to proxy the websockets to a custom subdomain, and access websockets through that subdomain on port 80/443 instead. Also I'm running php artisan websockets:serve --port=80, which is the default proxy port, and makes so there is no need for ws.lintex.local:6001.

This is my .lando.yml. I hope it might help someone stumbling upon this issue.

name: lintex
recipe: laravel
config:
  webroot: public
  php: '7.4'
  ssl: true
  composer_version: '2.0.4'
  via: nginx
  database: mysql:8.0
  cache: redis
excludes:
  - vendor
proxy:
  appserver_nginx:
    - lintex.local
  websockets:
    - ws.lintex.local
services:
  database:
    type: mysql:8.0
    portforward: 3306
    creds:
      user: lintex
      password: lintex
      database: lintex
  horizon:
    type: php:7.4
    via: cli
    command: /app/lando.horizon.sh
    overrides:
      depends_on:
        - database
  websockets:
    type: php:7.4
    via: cli
    ssl: true
    command: /app/lando.websockets.sh
    scanner: false
    overrides:
      depends_on:
        - database
bindAddress: "0.0.0.0" # that probably goes in your global .lando/config.yml file

@sdunham
Copy link

sdunham commented Apr 6, 2021

@eminos Thanks for posting an update on this, it was super useful for me!

Some additional context I'll add from my own semi-related case, in case it's useful to others:

  • This line from the above landofile is very important, as it's what allows external access to the app's services: bindAddress: "0.0.0.0"
  • In my case, I only needed to expose a single process running within one of my services so it could be accessed from another service. Instead of globally setting bindAddress to 0.0.0.0, I was able to just bind that process to 0.0.0.0 instead of 127.0.0.1. That ended up looking like this in my case: beanstalkd -l 0.0.0.0 -p 11303
  • By binding the process to 0.0.0.0 on port 11303, I was then able to connect to the process from another service. For example, using telnet to connect from another service would look something like this: telnet {service-name}.{app-name}.internal 11303

@rtfm-47 rtfm-47 transferred this issue from lando/lando Dec 21, 2021
@aschkenasy
Copy link

@eminos I know this is an old issue, but do you remember if you started the server by setting a port flag?
php artisan websockets:serve --port=443
to match the proxied domain? or the host flag?
php artisan websocket:serve --host=<proxied lando host>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants