
NOTE: This guide is for apps generated on Phoenix 1.6.3 or later, where deployment is streamlined significantly.
If you’re on an earlier version and can’t upgrade, check out our legacy deployment guide.
Preparation
If you don’t already have Elixir and Phoenix installed, get them set up before starting this guide. When you install Elixir, the Mix build tool ships with it. You can install the Phoenix project generatorphx.new from a Hex package as follows:
Generate the app and deploy with Postgres
If you just want to see how Fly.io deployment works, this is the section to focus on. Here we’ll bootstrap the app and deploy it with a Postgres database. First, install flyctl, the Fly.io CLI, and sign up to Fly.io if you haven’t already. Now let’s generate a shiny, new Phoenix app:fly launch from the newly-created project directory, the launcher provides some defaults for your new app, and gives you the option to tweak the settings.
Run:
y at the prompt to open the Fly Launch page, and make the following changes to your app config:
- Change the default app name and region, if needed.
- For Databases, select Fly Postgres, give the Postgres database app a name (for example, your app name with
-dbappended) and choose a configuration.
- Run the deployment setup task
- Build the image
- Set secrets required by (
SECRET_KEY_BASE, for example) - Deploy the application in your selected region
Make sure to note your Postgres credentials from the output.
fly apps open to see your deployed app in action.
Try a few other commands:
fly logs- Tail your application logsfly status- App deployment detailsfly status -a postgres-database-app-name- Database deployment detailsfly deploy- Deploy the application after making changes
fly launch command detected that we are using Phoenix, set up a Fly app, created a Fly Postgres app and configured it for us, updated our Dockerfile, and created special modules and scripts to run ecto migrations for us!
Storing secrets on Fly.io
You may also have some secrets you’d like set on your app. Usefly secrets to configure those.
Deploying again
When you want to deploy changes to your application, usefly deploy.
fly deploy command uses a Fly.io remote builder app to build the image.
You can always check on the status of a deploy:
Important IPv6 settings
Theflyctl command attempts to modify your project’s Dockerfile and append the following lines: