lando / php

The Official Lando PHP plugin.
https://docs.lando.dev/php
GNU General Public License v3.0
14 stars 15 forks source link

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

Open eminos opened 3 years ago

eminos commented 3 years ago

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 commented 3 years ago

@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 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

@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:

aschkenasy commented 1 year ago

@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>