Search⌘ K
AI Features

Deploying with Mix

Explore how to deploy Elixir applications using Mix commands. Understand managing production environments, optimizing VM configurations, and handling multi-server deployments effectively for robust application uptime.

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:

C++
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 of mix run --no-halt, we’ll execute mix phx.server, still setting the Mix environment to prod.

  • 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 the mix.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 ...