How to deploy Phoenix App with Fly.io

Chai Phonbopit
2 min readMay 23, 2023

--

Hi There! 👋 I am currently learning Elixir and Phoenix. After I finish my sample project, I want to build and deploy an app. I was looking for services like Heroku or Vercel, After doing some research. I found Fly.io and wanted to try it.

Install flyctl

Flyctl is fly.io command-line version. You can create an account and deploy your application from the terminal.

If you have Homebrew installed, you can install flycli by running:

brew install flyctl

Or run with bash script:

curl -L https://fly.io/install.sh | sh

Create Phoenix App

I create a basic app without mail, dashboard and ecto, I only want to test how does it work.

mix phx.new ahoy --no-mailer --no-dashboard --no-gettext --no-ecto

After project created, Run a script to create a fly.io app from the root directory of your project:

fly launch

The launcher will ask you a few questions, for example:

  • Select a deployment region
  • Would you like to set up Postgresql or Redis?
  • Would you like to deploy now? -> I selected No
  • Set a secret ( SECRET_KEY_BASE , for example)
Detected a Phoenix app
? Choose an app name (leave blank to generate one):

? Choose a region for deployment:
? Would you like to set up a Postgresql database now?
? Would you like to set up an Upstash Redis database now?
Preparing system for Elixir builds
Installing application dependencies
Running Docker release generator
Wrote config file fly.toml
? Would you like to deploy now?

✓ Configuration is valid

Your Phoenix app should be ready for deployment!.

If you need something else, post on our community forum at https://community.fly.io.

When you're ready to deploy, use 'fly deploy'.

The configuration file is fly.toml , containing all your configuration above step, for example, app name, region and environment variables.

Deploying an App

Before we deploy, we generate a random secret key and setup to Fly.io secret key.

Generate random secret key:

mix phx.gen.secret

Setup secret key

fly secrets set SECRET_KEY_BASE=<YOUR_SECRET_KEY>

Lastly, Deploy an application

fly deploy

🎉 🎉🎉 Go to your fly.io dashboard and see your app information.

Happy Coding ❤️

--

--

Chai Phonbopit
Chai Phonbopit

No responses yet