# First time laravel deploying

**URL:** <https://community.fly.io/t/first-time-laravel-deploying/20873>\
**Category:** Questions / Help\
**Tags:** postgres, laravel, login-only\
**Created:** [July 19, 2024, 12:24pm UTC](https://community.fly.io/t/first-time-laravel-deploying/20873 "2024-07-19T12:24:02Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![librocreates](https://avatars.discourse-cdn.com/v4/letter/l/47e85d/32.png) [@librocreates](https://community.fly.io/u/librocreates)\
**Post date:** [July 19, 2024, 12:24pm UTC](https://community.fly.io/t/first-time-laravel-deploying/20873/1 "2024-07-19T12:24:02Z")

</div>

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

 ![Screenshot 2024-07-19 alle 14.18.55](https://global.discourse-cdn.com/fly1/original/3X/6/b/6b0a94d4f6604bf32b438c91f215046555f64409.png)

---

<div class="post-metadata">

**Author:** ![Johannes-Fly](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/johannes-fly/32/5888_2.png) [@Johannes-Fly](https://community.fly.io/u/Johannes-Fly)\
**Post date:** [July 22, 2024, 9:00am UTC](https://community.fly.io/t/first-time-laravel-deploying/20873/2 "2024-07-22T09:00:54Z")

</div>

Hi!

It could be possible that this issue was caused by swoole version 6.0.0, like in [this stackoverflow thread](https://stackoverflow.com/questions/78669556/possible-bug-with-php-pdo-and-with-postgresql).  
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](http://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](https://www.php.net/manual/en/function.swoole-version.php).

---

<div class="post-metadata">

**Author:** ![librocreates](https://avatars.discourse-cdn.com/v4/letter/l/47e85d/32.png) [@librocreates](https://community.fly.io/u/librocreates)\
**Post date:** [July 22, 2024, 9:33am UTC](https://community.fly.io/t/first-time-laravel-deploying/20873/3 "2024-07-22T09:33:29Z")

</div>

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

 ![Screenshot 2024-07-22 alle 11.27.34](https://global.discourse-cdn.com/fly1/original/3X/f/7/f724c3d8d2ebed8484402a123a9b2da215bd18be.png)

 ![Screenshot 2024-07-22 alle 11.27.26](https://global.discourse-cdn.com/fly1/original/3X/7/0/7032232309c065f197a1e5026a9dc1e995426a01.png)

---

<div class="post-metadata">

**Author:** ![Johannes-Fly](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/johannes-fly/32/5888_2.png) [@Johannes-Fly](https://community.fly.io/u/Johannes-Fly)\
**Post date:** [July 22, 2024, 9:43am UTC](https://community.fly.io/t/first-time-laravel-deploying/20873/4 "2024-07-22T09:43:27Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![librocreates](https://avatars.discourse-cdn.com/v4/letter/l/47e85d/32.png) [@librocreates](https://community.fly.io/u/librocreates)\
**Post date:** [July 22, 2024, 1:55pm UTC](https://community.fly.io/t/first-time-laravel-deploying/20873/6 "2024-07-22T13:55:39Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![Johannes-Fly](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/johannes-fly/32/5888_2.png) [@Johannes-Fly](https://community.fly.io/u/Johannes-Fly)\
**Post date:** [July 22, 2024, 2:49pm UTC](https://community.fly.io/t/first-time-laravel-deploying/20873/7 "2024-07-22T14:49:45Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![librocreates](https://avatars.discourse-cdn.com/v4/letter/l/47e85d/32.png) [@librocreates](https://community.fly.io/u/librocreates)\
**Post date:** [July 22, 2024, 3:15pm UTC](https://community.fly.io/t/first-time-laravel-deploying/20873/8 "2024-07-22T15:15:12Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Johannes-Fly](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/johannes-fly/32/5888_2.png) [@Johannes-Fly](https://community.fly.io/u/Johannes-Fly)\
**Post date:** [July 22, 2024, 3:48pm UTC](https://community.fly.io/t/first-time-laravel-deploying/20873/9 "2024-07-22T15:48:34Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![librocreates](https://avatars.discourse-cdn.com/v4/letter/l/47e85d/32.png) [@librocreates](https://community.fly.io/u/librocreates)\
**Post date:** [July 23, 2024, 9:01am UTC](https://community.fly.io/t/first-time-laravel-deploying/20873/10 "2024-07-23T09:01:35Z")

</div>

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??_

 ![Screenshot 2024-07-23 alle 11.00.27](https://global.discourse-cdn.com/fly1/original/3X/5/d/5d6c68b802eb364296b48def7d1570dcee4e4bdd.png)

---

<div class="post-metadata">

**Author:** ![Johannes-Fly](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/johannes-fly/32/5888_2.png) [@Johannes-Fly](https://community.fly.io/u/Johannes-Fly)\
**Post date:** [July 23, 2024, 9:46am UTC](https://community.fly.io/t/first-time-laravel-deploying/20873/11 "2024-07-23T09:46:53Z")

</div>

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](https://fly.io/docs/networking/private-networking/#flycast-private-fly-proxy-services). 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 `.flycast`address. 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](http://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!

---

<div class="post-metadata">

**Author:** ![librocreates](https://avatars.discourse-cdn.com/v4/letter/l/47e85d/32.png) [@librocreates](https://community.fly.io/u/librocreates)\
**Post date:** [July 23, 2024, 6:53pm UTC](https://community.fly.io/t/first-time-laravel-deploying/20873/12 "2024-07-23T18:53:36Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Johannes-Fly](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/johannes-fly/32/5888_2.png) [@Johannes-Fly](https://community.fly.io/u/Johannes-Fly)\
**Post date:** [July 24, 2024, 7:21am UTC](https://community.fly.io/t/first-time-laravel-deploying/20873/13 "2024-07-24T07:21:36Z")

</div>

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](https://fly.io/docs/laravel/database-guides/laravel-pgsql/#connect-from-a-laravel-fly-app-by-attachment)

---

<div class="post-metadata">

**Author:** ![librocreates](https://avatars.discourse-cdn.com/v4/letter/l/47e85d/32.png) [@librocreates](https://community.fly.io/u/librocreates)\
**Post date:** [July 24, 2024, 7:49am UTC](https://community.fly.io/t/first-time-laravel-deploying/20873/14 "2024-07-24T07:49:24Z")

</div>

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 😂

---

<div class="post-metadata">

**Author:** ![Johannes-Fly](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/johannes-fly/32/5888_2.png) [@Johannes-Fly](https://community.fly.io/u/Johannes-Fly)\
**Post date:** [July 24, 2024, 12:26pm UTC](https://community.fly.io/t/first-time-laravel-deploying/20873/15 "2024-07-24T12:26:07Z")

</div>

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](https://fly.io/docs/flyctl/proxy/))?

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/fly1/original/3X/6/e/6e8955d00cb218e186ebbe3a6ab06fefdce15290.svg) [@system](https://community.fly.io/u/system)\
**Post date:** [July 31, 2024, 12:26pm UTC](https://community.fly.io/t/first-time-laravel-deploying/20873/16 "2024-07-31T12:26:16Z")

</div>

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