# Deploying for the first time - environment variable DATABASE\_URL is missing

**URL:** <https://community.fly.io/t/deploying-for-the-first-time-environment-variable-database-url-is-missing/20192>\
**Category:** Questions / Help\
**Tags:** elixir, postgres, login-only\
**Created:** [June 4, 2024, 6:00am UTC](https://community.fly.io/t/deploying-for-the-first-time-environment-variable-database-url-is-missing/20192 "2024-06-04T06:00:07Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![tyndale](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/tyndale/32/41827_2.png) [@tyndale](https://community.fly.io/u/tyndale)\
**Post date:** [June 4, 2024, 6:00am UTC](https://community.fly.io/t/deploying-for-the-first-time-environment-variable-database-url-is-missing/20192/1 "2024-06-04T06:00:07Z")

</div>

Hi I’m deploying someone else’s elixir/phoenix code ([GitHub - algora-io/tv: Open source Twitch for developers](https://github.com/algora-io/tv)) and it already had a toml file, which I tweaked.

I did `fly launch` and I got this error:

`environment variable DATABASE_URL is missing`

I have a `.env` file with the DATABASE\_URL set. how do I inject into the runtime environment?

Regards,

```auto
Error release_command failed running on machine e824503a7e7178 with exit code 1.
Check its logs: here's the last 100 lines below, or run 'fly logs -i e824503a7e7178':
  Pulling container image registry.fly.io/ca-sidha-teevee:deployment-01HZGGXAVCEJRR549WRDWJXN9H
  Successfully prepared image registry.fly.io/ca-sidha-teevee:deployment-01HZGGXAVCEJRR549WRDWJXN9H (26.130196034s)
  Configuring firecracker
  2024-06-04T02:32:10.012102490 [01HZGHD2Q9E4YNE0J517B4R771:main] Running Firecracker v1.7.0
  [0.038635] Spectre V2 : WARNING: Unprivileged eBPF is enabled with eIBRS on, data leaks possible via Spectre v2 BHB attacks!
  [0.042699] PCI: Fatal: No config space access function found
   INFO Starting init (commit: d772ddd9)...
   INFO Preparing to run: `/app/bin/migrate` as nobody
   INFO [fly api proxy] listening at /.fly/api
  2024/06/04 02:32:10 INFO SSH listening listen_address=[fdaa:0:3adb:a7b:234:1623:ad45:2]:22 dns_server=[fdaa::3]:53
  Machine created and started in 27.925s
  ERROR! Config provider Config.Reader failed with:
  ** (RuntimeError) environment variable DATABASE_URL is missing.
  For example: ecto://USER:PASS@HOST/DATABASE
      /app/releases/0.1.0/runtime.exs:24: (file)
      (elixir 1.15.7) src/elixir.erl:396: :elixir.eval_external_handler/3
      (stdlib 5.2) erl_eval.erl:750: :erl_eval.do_apply/7
      (stdlib 5.2) erl_eval.erl:494: :erl_eval.expr/6
      (stdlib 5.2) erl_eval.erl:136: :erl_eval.exprs/6
      (elixir 1.15.7) src/elixir.erl:375: :elixir.eval_forms/4
      (elixir 1.15.7) lib/module/parallel_checker.ex:112: Module.ParallelChecker.verify/1
      (elixir 1.15.7) lib/code.ex:543: Code.validated_eval_string/3

```

---

<div class="post-metadata">

**Author:** ![Eiley](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/eiley/32/13960_2.png) [@Eiley](https://community.fly.io/u/Eiley)\
**Post date:** [June 4, 2024, 8:10am UTC](https://community.fly.io/t/deploying-for-the-first-time-environment-variable-database-url-is-missing/20192/2 "2024-06-04T08:10:47Z")

</div>

Maybe you haven’t set the variable.

You can do it with the cli like this:

```auto
fly secrets set DATABASE_URL=<database_url> --stage

```

And then you can deploy and it will be set.

You can find more info here: [Secrets and Fly Apps · Fly Docs](https://fly.io/docs/reference/secrets/)

---

<div class="post-metadata">

**Author:** ![tyndale](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/tyndale/32/41827_2.png) [@tyndale](https://community.fly.io/u/tyndale)\
**Post date:** [June 4, 2024, 3:55pm UTC](https://community.fly.io/t/deploying-for-the-first-time-environment-variable-database-url-is-missing/20192/3 "2024-06-04T15:55:13Z")

</div>

Thanks!

---

<div class="post-metadata">

**Author:** ![tyndale](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/tyndale/32/41827_2.png) [@tyndale](https://community.fly.io/u/tyndale)\
**Post date:** [June 4, 2024, 8:23pm UTC](https://community.fly.io/t/deploying-for-the-first-time-environment-variable-database-url-is-missing/20192/4 "2024-06-04T20:23:56Z")

</div>

So I’m looking into the code further and my question is the reason the app doesn’t have a DATABASE\_URL is because it’s configured to use the `fly_postgres` hex package so that it is in a primary/replica configuration? How do I configure my fly app to use a primary/replica configuration?

---

<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:** [June 11, 2024, 8:24pm UTC](https://community.fly.io/t/deploying-for-the-first-time-environment-variable-database-url-is-missing/20192/5 "2024-06-11T20:24:26Z")

</div>

Closed on June 11, 2024, 8:24pm UTC

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