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 runcommand will compile and start the current application and all its dependencies. -
The
--no-haltcommand 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=prodcommand ensures that our application is running in the production environment with the relevant configurations. One of those configurations is the:start_permanentoption, which can be found in themix.exsfile: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 ...