The following instructions allow a user to go from zero to hero with Gigalixir, Phoenix, and Mix. This guide uses the latest versions:

Last updated/tested on 2024-02-12.

Gigalixir recommends using Elixir Releases for the startup and runtime efficiency.

Prerequisites

This guide utilizes these tools:

With these tools set up, let’s get started!

Install Erlang, Elixir, and Node

Use ASDF and NVM to install the versions we want.

asdf install erlang 26.2.2
asdf install elixir 1.16.1
nvm install v21.6.1

Now set the versions as active.

asdf local erlang 26.2.2
asdf local elixir 1.16.1
nvm use 21.6.1

Install Phoenix Framework

Install hex

mix local.hex

Get the latest version of Phoenix and install it.

mix archive.install hex phx_new

Create a new phoenix application

Create the phoenix application, in this case mix_example is the name of the application. You will probably want use some other name.

mix phx.new mix_example --install

Now move into the new project directory and make it a git repository.

cd mix_example
git init
git add .
git commit -m "initial commit: mix phx.new"

Set the versions for the buildpacks to use

Gigalixir uses a buildpack system. We can set the versions in the elixir_buildpack.config and phoenix_static_buildpack.config to ensure a consistent environment between development and production.

echo "elixir_version=1.16.1" > elixir_buildpack.config
echo "erlang_version=26.2.2" >> elixir_buildpack.config
echo "node_version=21.6.1" > phoenix_static_buildpack.config

git add elixir_buildpack.config phoenix_static_buildpack.config
git commit -m "set elixir, erlang, and node version"

Esbuild support

Gigalixir has esbuild installed, but we need to tell the buildpacks how to compile our assets.

mkdir -p assets

echo '{
  "scripts": {
    "deploy": "cd .. && mix assets.deploy && rm -f _build/esbuild"
  }
}' > assets/package.json

git add assets/package.json
git commit -m "compile assets on build"

Create the gigalixir app and database

The default phoenix application is going to require a DATABASE_URL. In the below example, we create a free tier database. If you plan to use this application for production, consider the [standard tier database].

gigalixir create
gigalixir pg:create --free

Push to gigalixir and prosper

We are ready to deploy.

git push -u gigalixir main

You can monitor the deployment using gigalixir ps. If you run into issues, check gigalixir logs.

As always, if you hit any issues, we’re one email away to help. Just write us at Gigalixir Support.