Learn how to deploy Phoenix applications using Fly.io, releases, Docker, and generic VPS deployment
Learn how to deploy Phoenix applications using Fly.io, releases, Docker, and generic VPS deployment.
Super quick:
flyctl auth login
fly launch
in your Phoenix app root directoryThat’s it! Fly handles Dockerfile and config automatically.
Set Env Vars:
SECRET_KEY_BASE
(for encryption)DATABASE_PATH
(for SQLite, or DATABASE_URL
for Postgres)raise
in runtime.exs
mix phx.gen.secret
export SECRET_KEY_BASE=your_generated_key
export DATABASE_PATH=shopcore_prod.db
Install production deps only:
MIX_ENV=prod mix deps.get --only prod
Compile the app:
MIX_ENV=prod mix compile
Build front-end assets (if using HTML/CSS/JS):
MIX_ENV=prod mix assets.deploy
Run database migrations:
MIX_ENV=prod mix ecto.migrate
Start the server:
MIX_ENV=prod PORT=4001 mix phx.server
MIX_ENV=prod mix release --docker
# then start your app with the release scripts
mix phx.gen.release --docker
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.