Jeffrey Hicks

Jeffrey Hicks

Platform Eng @R360

20 - Phoenix crash course #20: Deployment

Learn how to deploy Phoenix applications using Fly.io, releases, Docker, and generic VPS deployment

By Daniel Bergholz • Aug 19, 2025

Learn how to deploy Phoenix applications using Fly.io, releases, Docker, and generic VPS deployment.

Deploying on Fly.io

Super quick:

  1. Install Fly CLI
  2. flyctl auth login
  3. Run fly launch in your Phoenix app root directory

That’s it! Fly handles Dockerfile and config automatically.

Generic Phoenix Deployment Steps

  1. Set Env Vars:

    • SECRET_KEY_BASE (for encryption)
    • DATABASE_PATH (for SQLite, or DATABASE_URL for Postgres)
    • Find required vars by searching raise in runtime.exs
    • Generate a secure key:
      mix phx.gen.secret
      export SECRET_KEY_BASE=your_generated_key
      export DATABASE_PATH=shopcore_prod.db
  2. Install production deps only:

    MIX_ENV=prod mix deps.get --only prod
  3. Compile the app:

    MIX_ENV=prod mix compile
  4. Build front-end assets (if using HTML/CSS/JS):

    MIX_ENV=prod mix assets.deploy
  5. Run database migrations:

    MIX_ENV=prod mix ecto.migrate
  6. Start the server:

    MIX_ENV=prod PORT=4001 mix phx.server

Releases (Self-contained deploys)

  • Use Elixir’s release mechanism to package app + Erlang VM + all dependencies into a standalone bundle
  • Makes deployment easy on servers with no Elixir/Erlang installed
  • For Docker:
    MIX_ENV=prod mix release --docker
    # then start your app with the release scripts

Docker

  • Official Phoenix Dockerfile automates all build & release steps for production
  • Resulting image only contains what’s needed to run your app—not a full Elixir dev environment
  • Fly.io generates a Dockerfile for you, but you can also generate one with:
    mix phx.gen.release --docker

Resources

Summary

Deployment is now straightforward with Phoenix, whether you use Fly.io (just a few commands), a generic VPS, or Docker. Use Mix tasks to set up environment, compile sources/assets, migrate DB, and optionally build a portable release for ultimate flexibility and dependency isolation.

Related

#phoenix-and-elixir #phoenix-crash-course #daniel-bergholz