How to fix "The app is not listening on the expected address" with laravel?

Hi everyone,

I have a laravel app running. When I deploy it with fly deploy, I get the following warning message:

WARNING The app is not listening on the expected address and will not be reachable by fly-proxy.
You can fix this by configuring your app to listen on the following addresses:
  - 0.0.0.0:8080 for machine 4d89622ce470d8 to reach a good state
Found these processes inside the machine with open listening sockets:
  PROCESS        | ADDRESSES
-----------------*---------------------------------------
  /.fly/hallpass | [fdaa:5:6e15:a7b:251:a81c:6107:2]:22

My fly.toml looks like this:

[env]
  APP_ENV = "production"
  APP_URL = "https://vivo-probe.de"
  APP_HOST="0.0.0.0"
  SERVER_HOST="0.0.0.0"
  HOST="0.0.0.0"
  APP_PORT = "8080"
  SERVER_PORT="8080"
  PORT = "8080"

[http_service]
  internal_port = 8080
  force_https = true

I have to say, I have no idea where else in Laravel I can set which addresses and on which ports my app listens to. I don’t know what exactly laravl runs with under fly.io, but I once saw nginx in the error message when an error occurred.

Does anyone have any idea what I can do to stop this error message from appearing?

Thanks in advance and best regards
Johannes Nazarov

Hi Johannes, great first name!

I don’t think you need anything in the [env] section except for APP_ENV and APP_URL, the others (APP_HOST, SERVER_HOST and so on) can be removed.

Your setup actually looks good, so I wonder if your app is running into errors? That would also cause that error message, since the app is not responding correctly to requests.

To recap, here’s how the routing works:
Normally, your Laravel app should run with port 8080. When an HTTP or HTTPS request comes in, those will be on port 80 (http) or 443 (https). The internal_port parameter is how Fly Proxy (the thing that routes the incoming requests to the correct place) knows what port your Laravel app is running on.

The error you’re seeing is quite generic: it just says that your app is not listening on port 8080. That could be a networking issue, or it could just be that your app has run into an error and wasn’t able to process the request.

Here are some things you could try:

  • SSH into your app by running fly ssh console in your app directory, and run php artisan serve there. What’s the output?
  • Check the logs in the fly.io dashboard. Are you seeing errors ?

Hi Johannes, nice to meet you!

The artisan serve output is:

Server running on [http://0.0.0.0:8080].  

I also have the following error message in my logs:

2024-08-12T12:26:06.918 proxy[6833274a757e48] ams [error] [PC01] instance refused connection. is your app listening on 0.0.0.0:8080? make sure it is not only listening on 127.0.0.1 (hint: look at your startup logs, servers often print the address they are listening on)

I assume this is the error message that is sent when deploying. After that, it no longer occurs and I can call up the app without any problems.

Any other ideas?

Hey again Johannes!

Am I correct to assume that the app works fine when you visit it in a browser?
We’ve been testing more and what could be happening is this:
The app takes a little while (less than a second) to boot up after deploying. Fly Proxy tests the app after deploying, and sometimes the app hasn’t completely booted up yet, and Fly Proxy complains that the app isn’t listening.
If that is the case, a possible fix is to add this to your fly.toml:

[[services.http_checks]]
    grace_period = "5s"

If that works, you could tighten the grace period to 2 seconds or even 1 second.

You can find more info about the grace period here: Troubleshoot your deployment · Fly Docs

Let me know if this helps!

Hello Johannes,

I tried with

 [[http_service.checks]]
    grace_period = "10s"

But when deploying I got Error: failed to update machine 6833274a757e48: Unrecoverable error: timeout reached waiting for health checks to pass for machine 6833274a757e48: failed to get VM 6833274a757e48: Get "https://api.machines.dev/v1/apps/vivo-probe/machines/6833274a757e48": net/http: request canceled

Using your variant

[[services.http_checks]]
    grace_period = "10s"

gives me another error:

Service has no processes set but app has 2 processes defined; update fly.toml to set processes for each service
WARNING: Service must expose at least one port. Add a [[services.ports]] section to fly.toml; Check docs at https://fly.io/docs/reference/configuration/#services-ports
 Validation for _services without ports_ will hard fail after February 15, 2024.
   ✘invalid app configuration
Error: App configuration is not valid

Here is my whole .env

# fly.toml app configuration file generated for vivo-probe on 2024-01-17T12:59:14+01:00
#
# See https://fly.io/docs/reference/configuration/ for information about how to use this file.
#
# Machine Operations: https://fly.io/docs/flyctl/machine-destroy/
# fly ssh console
#

app = "vivo-probe"
primary_region = "ams"
console_command = "php /var/www/html/artisan tinker"

[build]
  [build.args]
    NODE_VERSION = "20"
    PHP_VERSION = "8.2"

[env]
  APP_ENV = "production"
  APP_URL = "https://vivo-probe.de"
  LOG_CHANNEL = "stack"
  LOG_LEVEL = "info"
  LOG_STDERR_FORMATTER = "Monolog\\Formatter\\JsonFormatter"
  SESSION_DRIVER = "cookie"
  SESSION_SECURE_COOKIE = "true"
  DB_CONNECTION = "mysql"
  DB_HOST = "mysql-probe.internal"
  DB_DATABASE= "probe"
  MAIL_MAILER="smtp"
  MAIL_HOST="smtp.gmail.com"
  MAIL_PORT="465"
  #MAIL_USERNAME=user@gmail.com --> secrets
  #MAIL_PASSWORD="" --> secrets
  MAIL_ENCRYPTION="ssl"

[http_service]
  internal_port = 8080
  force_https = true
  auto_stop_machines = "off"
  auto_start_machines = true
  min_machines_running = 0
  processes = ["app"]

[processes]
  app = ""
  cron = "cron -f"

[[restart]]
  policy = "always"
  processes = ["app"]

[[vm]]
  cpu_kind = "shared"
  cpus = 1
  memory_mb = 256

[mounts]
  source="app_storage"
  destination="/var/www/html/storage/app"

Thank you very much for your help!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.