2

I'm deploying on aws with edeliver. The deploys run fine, but when I try to access the site in the console with curl localhost:8888, I get a connection refused error.

If I try to start the app with ./rel/bin/app_name console, I get a (RuntimeError) expected the PORT environment variable to be set. However my config/prod.exs looks like this.

use Mix.Config

config :elixir_deploy, ElixirDeployWeb.Endpoint,
  load_from_system_env: true,
  http: [port: 8888],
  ssl: false,
  url: [host: "example.com", port: 80],
  cache_static_manifest: "priv/static/cache_manifest.json"

config :logger, level: :info

import_config "prod.secret.exs"

What am I missing here? It works if I set a PORT=8888 before the manual start, but I'd rather start automatically with edeliver

Peter R
  • 3,185
  • 23
  • 43
  • Are you sure you're not overwriting the http port config later in the config? – Dogbert Nov 02 '17 at 09:09
  • @Dogbert Yes, the only other lines are `use Mix.Config` in the beginning, `config :logger, level: :info`, and `import_config "prod.secret.exs"` at the end. – Peter R Nov 02 '17 at 09:14

1 Answers1

5

You need to set load_from_system_env to false (or just remove that line). When it's true, Phoenix's default generated endpoint.ex will use the value of the PORT environment variable, and if it's not found, it'll raise an error.

if config[:load_from_system_env] do
  port = System.get_env("PORT") || raise "expected the PORT environment variable to be set"
  {:ok, Keyword.put(config, :http, [:inet6, port: port])}
else
  {:ok, config}
end

Source

Dogbert
  • 212,659
  • 41
  • 396
  • 397
  • I was too busy trying to get it to work on the next line. Couldn't see the forrest for the trees. Thanks. – Peter R Nov 02 '17 at 11:47