Elixir Today: Deploying Phoenix App on Heroku

1. Create an app using Phoenix Framework

> mix phx.new app-name
> mix ecto.create
> mix ecto.migrate
> npm install --prefix assets

2. Initialize local and remote Repository

> git init
> git add .
> git commit -m "Initial commit"
> git remote set-url origin <url>
> git push -U main

3. Sign up for a Heroku Account

4. Install Heroku CLI

5. Create and Setup a Heroku App

In your terminal.

  • via browser
> heroku login
  • via CLI
> heroku login -i

create heroku app

> heroku create

In your phoenix app directory

> heroku git:remote -a < heroku-app-name >

In your phoenix app directory

> heroku create --buildpack hashnuke/elixir

Create a new file elixir_buildpack.config in your app home folder and write this code. Be vigilant with your elixir and erlang versions.

# Elixir version

# Erlang version
# https://github.com/HashNuke/heroku-buildpack-elixir-otp-builds/blob/master/otp-versions

Create a Procfile and write this code

web: mix phx.server

At this moment, we are going to use Node, npm and Phoenix Static buildpack

> heroku buildpacks:add https://github.com/gjaldon/heroku-buildpack-phoenix-static.git

Buildpack added. Next release on < app-name > will use:
  1. https://github.com/HashNuke/heroku-buildpack-elixir.git
  2. https://github.com/gjaldon/heroku-buildpack-phoenix-static.git

Create a phoenix_static_buildpack.config file and write this code.

# Node.js version

Making our Project Ready for Heroku

Refer on the Phoenix Document

Create Env variables on Heroku

Refer on the Phoenix Document

Deploy Time

> git add .
> git commit -m "deployment time"
> git push 
> git push heroku main


Phoenix Framework Docs Heroku Docs

Did I lack something on this write up? comment down below.

Happy Coding!