connection to server failed postgres

I have launched a Laravel application connected to a PostgreSQL application here. At first glance it looked like it worked however I got this warning in my terminal: “The app is not listening on the expected address and will not be reachable by fly-proxy” not listening on I checked my .env file and my fly.toml file. This was after following the instructions for the easier automated approach. Help would be appreciated. Thank you.

Hi @roguerecursion, and welcome to!

Error cause
The error above is usually caused by a mismatch in the ports configured in the fly.toml of your app, and the port where your app serves out. If this is the issue, can you please match the ports used in both places. i.e. if you have http_services.internal_port = 8080, please make sure your app gets served on port 8080. For Laravel apps using the default generated Dockerfile from fly launch, the default port used is 8080. However, if it’s it’s served on another port, you’ll likely get the error you’re getting above, so please make sure they match!

If, after properly matching the ports in your fly.toml and Dockerfile, and you’re still getting the error, can you also share relevant Dockerfile and fly.toml details about the app throwing the error? Are you getting the error from your Laravel Fly app or your PostgreSQL Fly app?

You mentioned that you followed “instructions for the easier automated approach”, can you also share the link to the page you used for setting up the automated approach?

Yes, I followed the instructions in creating the fly apps. One represents my Laravel application and the other represents the Postgres db. I did the attachment process somewhere in the docs it referenced manual as being harder. Here is the doc I used to attach my fly app laravel to fly app postgres: 1. Laravel and PostgreSQL · Fly Docs
2.Attach or Detach a Fly App · Fly Docs.

After which I tried to register a user on my laravel application and I got this error from the fly app m

Then I looked at what you suggested. To see if the ports matched in the expose portion of the Dockerfile at this time it is exposing port 8080 and my laravel application is exposing port 8080 as seen below.

Now I normally host my application using Herd on windows 11 for development. The base port is 9000 on that. In my .env file I do not see any references to port at all. Was I suppose to set a port number in my .env for fly?

I see! Thanks for sharing those details and updating your Dockerfile. Your Dockerfile looks good! I’ve replicated the same error as you are receiving though, and I might just have a solution!

Can you please remove the DB_CONNECTION attribute from the fly.toml, redeploy, and see if that fixes the error? See, for context, I think setting that value instructs Laravel 11 to get the value of config.database.pgsql config array. Which uses default settings host and port 5432, when the config.database.pgsql.url value is not set.

Possible Context
It is added in our docs page to set the DB_CONNECTION value, but that was for Laravel 10, and not Laravel 11

What’s the difference though? See, although Laravel 10 would still get connection values from the config.database.pgsql array, it can use the DATABASE_URL set by Fly because Laravel 10 uses the DATABASE_URL env variable name to set its config.database.pgsql.url value.

For Laravel 11 on the other hand,’s DATABASE_URL will not work because Laravel 11 now uses the DB_URL env variable name for setting the value of config.database.pgsql.url.

Let me know if it works!

I have added the DB_URL argument to the fly.toml file at the beginning and got the error: ref the img below. Now I thought I just had to change the env var in my .env to DB_URL however there was no change I still got the same error ref img below.

It looks like it is still looking for my sqlite file. The odd thing is it is looking for [ gsql ] I thought it might have been an typo that I have introduced however that was not the case. Also at the very beginning of this when I created the laravel project. When I used fly launch to init fly for the first time. I had a warning that said that the project wasn’t listening “fly-proxy” not listening on” → Is this a problem even though the application is set on port 8080 in both the docker and toml files? Since now the error isn’t a connection issue that I can tell it just doesn’t know where the pgsql file is.


Hello again @roguerecursion! Thank you for your patience on following up on this! You’re right, it seems that instead of pgsql, your app is now using the sqlite driver, as you are no longer getting the error about connection to server at The logs also verifies this connection( Connection: sqlite ) .

The possible reasoning behind this sqlite driver usage is because Laravel 11 makes use of sqlite as the default database. I asked above to remove the DB_CONNECTION which resulted in the usage of the default database to be used(sqlite)!

Can you please revise your fly.toml file and set the DB_CONNECTION='pgsql', and also copy over the DATABASE_URL set by fly pg attach as the value of DB_URL, and redeploy your app?

fly secrets set DB_URL="<THE_DATABASE_URL_VALUE>"
fly deploy