The following instructions allow a user to go from zero to hero with Gigalixir, Phoenix, and Elixir Releases. This guide uses the latest versions:
Last updated/tested on 2023-12-05.
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.1.2
asdf install elixir 1.15.7
nvm install v21.4.0
Now set the versions as active.
asdf local erlang 26.1.2
asdf local elixir 1.15.7
nvm use 21.4.0
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 releases_example
is the name of the application.
You will probably want use some other name.
mix phx.new releases_example --install
Now move into the new project directory and make it a git repository.
cd releases_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.15.7" > elixir_buildpack.config
echo "erlang_version=26.1.2" >> elixir_buildpack.config
echo "node_version=21.4.0" > 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"
Use Elixir Releases instead of Mix
Newer versions of Elixir use a runtime.exs
file instead of releases.exs
.
Gigalixir’s buildpacks will want a releases.exs
to determine this is not a Mix deployment.
This file can be empty, it just needs to exist.
echo "# this file is here so Gigalixir uses Elixir Releases on deploy" \
> config/releases.exs
git add config/releases.exs
git commit -m "use elixir releases"
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].
APP_NAME=$(gigalixir create)
gigalixir pg:create --free
Setup the web endpoint
The newer versions of phoenix can quickly be deployed by setting the PHX_HOST
and PHX_SERVER
environment variables instead of editing the endpoint configuration.
For custom domains you will want to make further modifications.
gigalixir config:set PHX_HOST=${APP_NAME}.gigalixirapp.com
gigalixir config:set PHX_SERVER=true
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.