In BlogPost, Elixir

Elixir Phoenix Applications: Deploy to Heroku

Recently, I ended up deploying a small Phoenix application on Heroku. Coming from Rails, I ran into a few hiccups and this post is my attempt to document those.

elixir basics

Step 1: Configure Your Database

If you want to deploy to Heroku, the first step is to configure your database URL. Log in to Heroku to take the DATABASE_URL environment variable and add it to your prod.exs file.

In config/prod.exs:

Step 2: Generate and configure a secret key

Generate a secret key with this phoenix command:

Set an ENV variable on your Heroku server to store the secret key. In the example below, I set an ENV variable called SECRET_KEY_BASE on my Heroku server.

Step 3: Set up your other ENV variables

Specify a POOL_SIZE of 10 or less if you’re running on the free Heroku plan.

In my particular use case, I needed to connect to the YouTube API with an API key provided by Google. When I wanted to be able to connect to the API locally, I created a .env file.

To make it work, I had to issue a source .env every time I opened a new terminal window and ran my Phoenix application locally.

Step 4: Configure your buildpacks

You’ll need to configure an elixir buildpack.

To run iex -S mix on Heroku, set config_vars_to_export. Without this, you will get errors when you run iex -S mix on Heroku.

Summary

If you follow these steps in addition to the Phoenix documentation, you will be able to successfully deploy your phoenix application on Heroku.

Recent Posts
social media