Deploy a Phoenix App

This is a Phoenix/Elixir real time chat example based on dwyl/phoenix-chat-example. It has been lightly modified to run on Render.

A sample app based on this code is running at

  1. Create a new PostgreSQL database on Render.

  2. Fork render-examples/phoenix-chat-example and create a new Web Service, giving Render’s GitHub app permission to access your forked repo.

    Render supplies the PORT and RENDER_APP_HOSTNAME environment variables for config/prod.exs.

    config :chat, ChatWeb.Endpoint,
     load_from_system_env: true,
     http: [:inet6, port: System.get_env("PORT") || 4000], url: [host: System.get_env("RENDER_APP_HOSTNAME"), port: 80], cache_static_manifest: "priv/static/cache_manifest.json",
     secret_key_base: Map.fetch!(System.get_env(), "SECRET_KEY_BASE")

    If you add a custom domain to your Render app, don’t forget to change the host in url to your new domain.

    Render automatically manages and terminates SSL for your apps, so you don’t need to configure SSL in Phoenix.

  3. Use the following values during creation:

    Build Command: ./

    Here are the contents of

    #!/usr/bin/env bash
    export MIX_ENV=prod
    mix deps.get --only prod
    mix compile
    cd assets && npm install && npm run deploy && cd ..
    mix phx.digest
    mix ecto.migrate

    Start Command: mix phx.server

    Under the Advanced section, add two new environment variables:

    SECRET_KEY_BASEA sufficiently strong secret. You can generate a secret locally by running mix phx.gen.secret
    DATABASE_URLThe internal connection string of the database you created above.

That’s it! Your chat service will be live on your Render URL as soon as the build finishes.