Some Gotchas When Deploying an Elixir Phoenix App to Heroku

Shu Uesugi
2 min readMay 10, 2016

--

Note: My Phoenix version is set as 1.2.0-rc.

I followed this guide to deploy my Elixir Phoenix application to Heroku, but got stuck for ~1 hour. Here are some gotchas I noticed:

1. Boot Timeout

I kept getting this error:

# After git push heroku deploy
# and running heroku logs -t
Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch

Here’s what happened. My server was API only, and I had already deleted static directory and relevant code:

# 1. On config/prod.exs, I skipped this line from
# config my_app, MyApp.Endpoint
cache_static_manifest: "priv/static/manifest.json",
# 2. Removed this from lib/my_app/endpoint.ex
plug Plug.Static,
at: "/", from: :layover, gzip: false,
only: ~w(css fonts images js favicon.ico robots.txt)
# 3. Removed priv/static/**

Hence I thought I could skip adding the Phoenix Static Buildpack, too. This was a mistake. Apparently this buildpack did something equivalent of creating a Procfile, which contains the following:

# Procfile
web: mix phoenix.server

So after adding the above Procfile to the root level the server started working correctly.

2. Exporting Config

I kept noticing that the config variables that depended on environment variables were always nil.

# For heroku
heroku config:set SOME_KEY="foo"
# In prod.exs
config my_app, :some_key, System.get_env("SOME_KEY")
# In application code
Application.get_env(:my_app, :some_key) # nil

It turns out that I had to explicitly specify which environment variables will be used in elixir_buildpack.config:

config_vars_to_export=(DATABASE_URL SOME_KEY)

That’s all for now. Happy elixir coding!

Unlisted

--

--