First time laravel deploying

Hi
i’m trying to deploy a newly created Laravel app on Fly, but when i try and migrate Postgres it throws this error.
I’m a newbie with deploying stuff so i’m sure i missed something very easy but i can’t tell where
Every help is very appreciated

Hi!

It could be possible that this issue was caused by swoole version 6.0.0, like in this stackoverflow thread.
Would it be possible to check what version of swoole you have running, if any? You can do that with Tinker using the following steps:

  1. Open a shell connection to your app on fly.io with flyctl ssh console
  2. Navigate to your Laravel app directory, this will probably be /var/www/html
  3. Open a Tinker session with php artisan tinker
  4. execute swoole_version(). You can find more about that command in the php manual.

Hi, thank you for your answer
Yeah i just checked, and i’m running version 5.1.3

I’ll upload a different version of the error message directly from the console, maybe it’s better to see

What database are you using? The server name librotest-pg.flycast and the port being 5432 would suggest you’re using Postgres, but the error mentions Connection: sqlite… Could it be possible that your DB_CONNECTION environment variable is set to sqlite but you’re trying to connect to a postgres database?

I’ve checked and I’m using a Postgres database, with both the .env and in the fly.toml set as pgsql it still gives me that error…

The fact that the error message says Connection: sqlite still seems odd to me. Could you check what the result is of running config(DB_CONNECTION) and env(DB_CONNECTION) in Tinker? The steps to open Tinker are outlined in my previous response.

Other things I could think of:

  • Did you set the DB_CONNECTION as a secret? You can check your secrets by running flyctl secrets list .
  • Did you change anything in the config/database.php file?

I set the DB_CONNECTION as secret, but in the env and config it says undefined constant “DB_CONNECTION”

I didn’t change the dabatase.php file, never touched it

Could you set the secret again to pgsql ? Or you could unset the secret altogether, since you already have it defined in your fly.toml. This way we can be 100% sure that that setting is correct.

If that isn’t the issue we can debug further.

I set it again just to be sure as you said, and the only thing that’s changed is that now it actually says pgsql instead of sqlite xD
The error is the same tho

is it the beginning of something??

Okay, now that we eliminated that issue we can debug further. I see that your database hostname is libroarchive-pg.flycast . There’s actually two ways of connecting apps in the same organization (so for you, the organization is Stefano Libro and the apps in that organization are libroarchive and libroarchive-pg):

  • Using .internal: connect directly to the app (without Fly Proxy in between) by using .internal.
  • Using .flycast: connect to the app using Fly Proxy. A Flycast address is an app-wide IPv6 address that the Fly Proxy can route to privately. Use a Flycast address to direct private network traffic through the Fly Proxy to take advantage of features like geographically aware load balancing and autostart/autostop based on traffic.

I suspect that your postgress app isn’t setup correctly to use .flycast, you can find the steps for that here: Private Networking · Fly Docs. The reason for that is that I don’t see an IPv6 address allocated for your postgres app. I could be wrong though.

So I think there are two options: use a .internal address or check if your app’s setup is 100% correct to be able to use a .flycastaddress. The link above should take you to the docs to set up Flycast, but here is the snippet I think you’ll need:

The general flow for setting up Flycast is:

  1. Allocate a private IPv6 address for your app on one of your Fly.io organization networks.
  2. Make sure your app binds to 0.0.0.0:port. Binding to fly-local-6pn:<port> is insufficient for Flycast.
  3. Expose services in your app’s fly.toml [services] or [http_service] block; do not use force_https as Flycast is HTTP-only.
  4. Deploy your app.
  5. Access the services on the private IP from the target organization network.

Let me know if that helps!

I re-set the secrets regarding the db using the .internal hostname instead of the flycast i had previously and now it’s saying this

SQLSTATE[08006] [7] Connection refused Is the server running on that host and accepting TCP/IP connections?

I tried connecting to it with fly postgres connect and it works, i can see the db created and stuff.
the Fly dashboard also tells me the app libroarchive-pg is up and running

Please lend me your help one time again and thanks for everything until now

Hmm, strange that that didn’t work. I do have another trick up my sleeve though!

Is it possible that you’re using Laravel 11? If you are, you should set a secret DB_URL variable, that contains the database url. It used to be DATABASE_URL before Laravel 11. You can find more info here: Laravel and PostgreSQL · Fly Docs

Yeah i’m using it, but i already saw it on the docs that i needed that extra secret and i already put it!
that’s why i’m confused :joy:

Hmh, that’s strange.
Some sanity checks:

  • Both your laravel and postgres apps are running in the same organization?
  • Maybe try removing the postgres app and recreating it with flyctl postgres create and fly postgres attach
  • maybe try connecting to your postgres app from your IDE, by using fly proxy to connect your localhost to the postgres app (more info here: fly proxy · Fly Docs)?

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