Deploying with Mix
Learn how to deploy your application with mix.
We'll cover the following...
Some basic mix commands
The emergence of deployment tools within Git and Elixir’s basic tooling makes it pretty simple to stand up a dead-simple deployment strategy for a single machine. The easiest way to run an Elixir application in production is by fetching or pushing the source code to our servers and calling this command:
MIX_ENV=prod mix run --no-halt
Let’s break the command:
-
The
mix run
command will compile and start the current application and all its dependencies. -
The
--no-halt
command guarantees Elixir won’t terminate just after the application is booted. Phoenix is similar. Instead ofmix run --no-halt
, we’ll executemix phx.server
, still setting the Mix environment toprod
. -
The
MIX_ENV=prod
command ensures that our application is running in the production environment with the relevant configurations. One of those configurations is the:start_permanent
option, which can be found in themix.exs
file:start_permanent: Mix.env == :prod
Each application runs as :temporary
or :permanent
. If a permanent application shuts down, it automatically causes the whole VM to shut down too, so something else can restart ...