{"__v":9,"_id":"56a75c30fc62900d00024be4","category":{"__v":1,"_id":"56a75c2cfc62900d00024bc5","pages":["56a75c30fc62900d00024be3","56a75c30fc62900d00024be4","56a75c30fc62900d00024be5"],"project":"54348ec95b10711400c6c445","version":"56a75c2cfc62900d00024bc1","reference":false,"createdAt":"2015-06-18T21:59:42.796Z","from_sync":false,"order":3,"slug":"deployment","title":"Deployment"},"parentDoc":null,"project":"54348ec95b10711400c6c445","user":"5435b410495d5d0800f3a603","version":{"__v":1,"_id":"56a75c2cfc62900d00024bc1","project":"54348ec95b10711400c6c445","createdAt":"2016-01-26T11:44:44.064Z","releaseDate":"2016-01-26T11:44:44.064Z","categories":["56a75c2cfc62900d00024bc2","56a75c2cfc62900d00024bc3","56a75c2cfc62900d00024bc4","56a75c2cfc62900d00024bc5","56a75c2cfc62900d00024bc6"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"1.1.4","version":"1.1.4"},"updates":["55e746b9e06f4b190080dbdf","5601df57fb9f160d00f2986d","56bb3b9d68be933500aeea53","56c3fabde1e4190d003429cf","571388a645e2090e001e5c50"],"createdAt":"2015-07-18T20:33:00.584Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":1,"body":"### What we'll need\n\nThe only thing we'll need for this guide is a working Phoenix application. For those of us who need a simple application to deploy, please follow the [Up and Running guide](http://www.phoenixframework.org/docs/up-and-running).\n\n### Goals\n\nOur main goal for this guide is to get a Phoenix application running on Heroku.\n\n## Steps\n\nLet's separate this process into a few steps so we can keep track of where we are.\n\n- Initialize Git repository\n- Sign up for Heroku\n- Install the Heroku Toolbelt\n- Create the Heroku application\n- Add the Phoenix static buildpack\n- Make our project Heroku-ready\n- Deploy time!\n- Useful Heroku commands\n\n## Initializing Git repository\n\n[Git](https://git-scm.com/) is a popular decentralized revision control system and is also used to deploy apps to Heroku.\n\nBefore we can push to Heroku we'll need to initialize a local Git repository and commit our files to it. We can do so by running the following commands in our project directory:\n\n```console\n$ git init\n$ git add .\n$ git commit -m \"Initial commit\"\n```\n\nHeroku offers some great information on how it is using Git [here](https://devcenter.heroku.com/articles/git#tracking-your-app-in-git).\n\n## Signing up for Heroku\n\nSigning up to Heroku is very simple, just head over to [https://signup.heroku.com/](https://signup.heroku.com/) and fill in the form.\n\nThe Free plan will give us one web [dyno](https://devcenter.heroku.com/articles/dynos#dynos) and one worker dyno, as well as a PostgreSQL and Redis instance for free.\n\nThese are meant to be used for testing and development, and come with some limitations. In order to run a production application, please consider upgrading to a paid plan.\n\n## Installing the Heroku Toolbelt\n\nOnce we have signed up, we can download the correct version of the Heroku Toolbelt for our system [here](https://toolbelt.heroku.com/).\n\nThe Heroku CLI, part of the Toolbelt, is useful to create Heroku applications, list currently running dynos for an existing application, tail logs or run one-off commands (mix tasks for instance).\n\n## Creating the Heroku Application\n\nNow that we have the Toolbelt installed, let's create the Heroku application. In our project directory, run:\n\n> Note: the first time we use a Heroku command, it may prompt us to log in. If this happens, just enter the email and password you specified during signup.\n\n```console\n$ heroku create --buildpack \"https://github.com/HashNuke/heroku-buildpack-elixir.git\"\nCreating mysterious-meadow-6277... done, stack is cedar-14\nBuildpack set. Next release on mysterious-meadow-6277 will use https://github.com/HashNuke/heroku-buildpack-elixir.git.\nhttps://mysterious-meadow-6277.herokuapp.com/ | https://git.heroku.com/mysterious-meadow-6277.git\nGit remote heroku added\n```\n\n> Note: the name of the Heroku application is the random string after \"Creating\" in the output above (mysterious-meadow-6277). This will be unique, so expect to see a different name from \"mysterious-meadow-6277\".\n\nThe `--buildpack` option we are passing allows us to specify the [Elixir buildpack](https://github.com/HashNuke/heroku-buildpack-elixir) we want Heroku to use.\nA [buildpack](https://devcenter.heroku.com/articles/buildpacks) is a convenient way of packaging framework and/or runtime support. In our case it's installing Erlang, Elixir, fetching our application dependencies, and so on, before we run it.\n\nThe URL in the output is the URL to our application. If we open it in our browser now, we will get the default Heroku welcome page.\n\n> Note: if we hadn't initialized our Git repository before we ran the `heroku create` command, we won't have our Heroku remote repository properly set up at this point. We can set that up manually by running: `heroku git:remote -a [our-app-name].`\n\n## Adding the Phoenix Static Buildpack\n\nWe need to compile static assets for a successful Phoenix deployment. The [Phoenix static buildpack](https://github.com/gjaldon/heroku-buildpack-phoenix-static) can take care of that for us, so let's add it now.\n\n```console\n$ heroku buildpacks:add https://github.com/gjaldon/heroku-buildpack-phoenix-static.git\nBuildpack added. Next release on mysterious-meadow-6277 will use:\n  1. https://github.com/HashNuke/heroku-buildpack-elixir.git\n  2. https://github.com/gjaldon/heroku-buildpack-phoenix-static.git\nRun `git push heroku master` to create a new release using these buildpacks.\n```\n\n## Making our Project Heroku-ready\n\nEvery new Phoenix project ships with a config file `config/prod.secret.exs` which stores configuration that should not be commited along with our source code. By default Phoenix adds it to our `.gitignore` file.\n\nThis works great except Heroku uses [environment variables](https://devcenter.heroku.com/articles/config-vars) to pass sensitive informations to our application. It means we need to make some changes to our config before we can deploy.\n\nFirst, let's make sure our secret key is loaded from Heroku's environment variables instead of `config/prod.secret.exs` by adding a `secret_key_base` line  in `config/prod.exs`:\n\n```elixir\nconfig :hello_phoenix, HelloPhoenix.Endpoint,\n  http: [port: {:system, \"PORT\"}],\n  url: [host: \"example.com\", port: 80],\n  cache_static_manifest: \"priv/static/manifest.json\",\n  secret_key_base: System.get_env(\"SECRET_KEY_BASE\")\n```\n\nThen, we'll add the production database configuration to `config/prod.exs`:\n\n```elixir\n# Configure your database\nconfig :hello_phoenix, HelloPhoenix.Repo,\n  adapter: Ecto.Adapters.Postgres,\n  url: System.get_env(\"DATABASE_URL\"),\n  pool_size: 20,\n  ssl: true\n```\n\nNow, let's tell Phoenix to use our Heroku URL and enforce we only use the SSL version of the website. Find the url line:\n\n```elixir\nurl: [host: \"example.com\", port: 80],\n```\n\n... and replace it with this (don't forget to replace `mysterious-meadow-6277` with your application name):\n\n```elixir\nurl: [scheme: \"https\", host: \"mysterious-meadow-6277.herokuapp.com\", port: 443],\nforce_ssl: [rewrite_on: [:x_forwarded_proto]],\n```\n\nSince our configuration is now handled using Heroku's environment variables, we don't need to import the `config/prod.secret.exs` file in `/config/prod.exs` any longer, so we can delete the following line:\n\n```elixir\nimport_config \"prod.secret.exs\"\n```\n\nOur `config/prod.exs` now looks like this:\n\n```elixir\nuse Mix.Config\n\n...\n\nconfig :hello_phoenix, HelloPhoenix.Endpoint,\n  http: [port: {:system, \"PORT\"}],\n  url: [scheme: \"https\", host: \"mysterious-meadow-6277.herokuapp.com\", port: 443],\n  force_ssl: [rewrite_on: [:x_forwarded_proto]],\n  cache_static_manifest: \"priv/static/manifest.json\",\n  secret_key_base: System.get_env(\"SECRET_KEY_BASE\")\n\n# Do not print debug messages in production\nconfig :logger, level: :info\n\n# Configure your database\nconfig :hello_phoenix, HelloPhoenix.Repo,\n  adapter: Ecto.Adapters.Postgres,\n  url: System.get_env(\"DATABASE_URL\"),\n  pool_size: 20,\n  ssl: true\n```\n\nFinally, we need to decrease the timeout for the websocket transport in `web/channels/user_socket.ex`:\n\n```elixir\ndefmodule HelloPhoenix.UserSocket do\n  use Phoenix.Socket\n\n  ...\n\n  ## Transports\n  transport :websocket, Phoenix.Transports.WebSocket,\n    timeout: 45_000\nend\n```\n\nThis ensures that any idle connections are closed by Phoenix before they reach Heroku's 55 second timeout window.\n\nLastly, we'll need to create a [Procfile](https://devcenter.heroku.com/articles/procfile) with the following:\n\n```\nweb: MIX_ENV=prod mix phoenix.server\n\n```\n\n## Creating Environment Variables in Heroku\n\nThe `DATABASE_URL` config var is automatically created by Heroku when we add the [Heroku Postgres add-on](https://elements.heroku.com/addons/heroku-postgresql). We can create the database via the heroku toolbelt:\n\n```console\nheroku addons:create heroku-postgresql:hobby-dev\n```\n\nWe still have to create the `SECRET_KEY_BASE` config based on a random string. First, use `mix phoenix.gen.secret` to get a new secret:\n\n```console\n$ mix phoenix.gen.secret\nxvafzY4y01jYuzLm3ecJqo008dVnU3CN4f+MamNd1Zue4pXvfvUjbiXT8akaIF53\n```\n\nYour random string will be different; don't use this example value.\n\nNow set it in Heroku:\n\n```console\n$ heroku config:set SECRET_KEY_BASE=\"xvafzY4y01jYuzLm3ecJqo008dVnU3CN4f+MamNd1Zue4pXvfvUjbiXT8akaIF53\"\nSetting config vars and restarting mysterious-meadow-6277... done, v3\nSECRET_KEY_BASE: xvafzY4y01jYuzLm3ecJqo008dVnU3CN4f+MamNd1Zue4pXvfvUjbiXT8akaIF53\n```\n\nIf you need to make any of your config variables available at compile time you will need to explicitly define which ones in a configuration file. Create a file `elixir_buildpack.config` in your applications root directory and add a line like: `config_vars_to_export=(DATABASE_URL MY_VAR)`. See [here](https://github.com/HashNuke/heroku-buildpack-elixir#specifying-config-vars-to-export-at-compile-time) for more information. \n\n## Deploy Time!\n\nOur project is now ready to be deployed on Heroku.\n\nLet's commit all our changes:\n\n```\n$ git add config/prod.exs\n$ git add Procfile\n$ git add web/channels/user_socket.ex\n$ git commit -m \"Use production config from Heroku ENV variables and decrease socket timeout\"\n```\n\nAnd deploy:\n\n```console\n$ git push heroku master\nCounting objects: 55, done.\nDelta compression using up to 8 threads.\nCompressing objects: 100% (49/49), done.\nWriting objects: 100% (55/55), 48.48 KiB | 0 bytes/s, done.\nTotal 55 (delta 1), reused 0 (delta 0)\nremote: Compressing source files... done.\nremote: Building source:\nremote:\nremote: -----> Multipack app detected\nremote: -----> Fetching custom git buildpack... done\nremote: -----> elixir app detected\nremote: -----> Checking Erlang and Elixir versions\nremote:        WARNING: elixir_buildpack.config wasn't found in the app\nremote:        Using default config from Elixir buildpack\nremote:        Will use the following versions:\nremote:        * Stack cedar-14\nremote:        * Erlang 17.5\nremote:        * Elixir 1.0.4\nremote:        Will export the following config vars:\nremote:        * Config vars DATABASE_URL\nremote:        * MIX_ENV=prod\nremote: -----> Stack changed, will rebuild\nremote: -----> Fetching Erlang 17.5\nremote: -----> Installing Erlang 17.5 (changed)\nremote:\nremote: -----> Fetching Elixir v1.0.4\nremote: -----> Installing Elixir v1.0.4 (changed)\nremote: -----> Installing Hex\nremote: 2015-07-07 00:04:00 URL:https://s3.amazonaws.com/s3.hex.pm/installs/1.0.0/hex.ez [262010/262010] ->\n\"/app/.mix/archives/hex.ez\" [1]\nremote: * creating /app/.mix/archives/hex.ez\nremote: -----> Installing rebar\nremote: * creating /app/.mix/rebar\nremote: -----> Fetching app dependencies with mix\nremote: Running dependency resolution\nremote: Dependency resolution completed successfully\nremote: [...]\nremote: -----> Compiling\nremote: [...]\nremote: Generated phoenix_heroku app\nremote: [...]\nremote: Consolidated protocols written to _build/prod/consolidated\nremote: -----> Creating .profile.d with env vars\nremote: -----> Fetching custom git buildpack... done\nremote: -----> Phoenix app detected\nremote:\nremote: -----> Loading configuration and environment\nremote:        Loading config...\nremote:        WARNING: phoenix_static_buildpack.config wasn't found in the app\nremote:        Using default config from Phoenix static buildpack\nremote:        Will use the following versions:\nremote:        * Node 0.12.4\nremote:        Will export the following config vars:\nremote:        * Config vars DATABASE_URL\nremote:        * MIX_ENV=prod\nremote:\nremote: -----> Installing binaries\nremote:        Downloading node 0.12.4...\nremote:        Installing node 0.12.4...\nremote:        Using default npm version\nremote:\nremote: -----> Building dependencies\nremote:        [...]\nremote:        Running default compile\nremote:               Building Phoenix static assets\nremote:        07 Jul 00:06:22 - info: compiled 3 files into 2 files, copied 3 in 3616ms\nremote:        Check your digested files at 'priv/static'.\nremote:\nremote: -----> Finalizing build\nremote:        Creating runtime environment\nremote:\nremote: -----> Discovering process types\nremote:        Procfile declares types     -> (web)\nremote:        Default types for Multipack -> web\nremote:\nremote: -----> Compressing... done, 82.1MB\nremote: -----> Launching... done, v5\nremote:        https://mysterious-meadow-6277.herokuapp.com/ deployed to Heroku\nremote:\nremote: Verifying deploy... done.\nTo https://git.heroku.com/mysterious-meadow-6277.git\n * [new branch]      master -> master\n```\n\nTyping `heroku open` in the terminal should launch a browser with the Phoenix welcome page opened. In case you are using Ecto to access a database, you will also need to run migrations after the first deploy:\n\n```console\n$ heroku run mix ecto.migrate\n```\n\nAnd that's it!\n\n## Useful Heroku Commands\n\nWe can look at the logs of our application by running the following command in our project directory:\n\n```console\n$ heroku logs # use --tail if you want to tail them\n```\n\nWe can also start an IEx session attached to our terminal for experimenting in our app's environment:\n\n```console\n$ heroku run iex -S mix\n```\n\nIn fact, we can run anything using the `heroku run` command, like the Ecto migration task from above:\n\n```console\n$ heroku run mix ecto.migrate\n```\n\n## Troubleshooting\n\n### Compilation Error\n\nOccasionally, an application will compile locally, but not on Heroku. The compilation error on Heroku will look something like this:\n\n```console\nremote: == Compilation error on file lib/postgrex/connection.ex ==\nremote: could not compile dependency :postgrex, \"mix compile\" failed. You can recompile this dependency with \"mix deps.compile postgrex\", update it with \"mix deps.update postgrex\" or clean it with \"mix deps.clean postgrex\"\nremote: ** (CompileError) lib/postgrex/connection.ex:207: Postgrex.Connection.__struct__/0 is undefined, cannot expand struct Postgrex.Connection\nremote:     (elixir) src/elixir_map.erl:58: :elixir_map.translate_struct/4\nremote:     (stdlib) lists.erl:1353: :lists.mapfoldl/3\nremote:     (stdlib) lists.erl:1354: :lists.mapfoldl/3\nremote: \nremote: \nremote:  !     Push rejected, failed to compile elixir app\nremote: \nremote: Verifying deploy...\nremote: \nremote: !   Push rejected to mysterious-meadow-6277.\nremote: \nTo https://git.heroku.com/mysterious-meadow-6277.git\n```\n\nThis has to do with stale dependencies which are not getting recompiled properly. It's possible to force Heroku to recompile all dependencies on each deploy, which should fix this problem. The way to do it is to add a new file called `elixir_buildpack.config` at the root of the application. The file should contain this line:\n\n```\nalways_rebuild=true\n```\n\nCommit this file to the repository and try to push again to Heroku.","excerpt":"","slug":"heroku","type":"basic","title":"Heroku"}
### What we'll need The only thing we'll need for this guide is a working Phoenix application. For those of us who need a simple application to deploy, please follow the [Up and Running guide](http://www.phoenixframework.org/docs/up-and-running). ### Goals Our main goal for this guide is to get a Phoenix application running on Heroku. ## Steps Let's separate this process into a few steps so we can keep track of where we are. - Initialize Git repository - Sign up for Heroku - Install the Heroku Toolbelt - Create the Heroku application - Add the Phoenix static buildpack - Make our project Heroku-ready - Deploy time! - Useful Heroku commands ## Initializing Git repository [Git](https://git-scm.com/) is a popular decentralized revision control system and is also used to deploy apps to Heroku. Before we can push to Heroku we'll need to initialize a local Git repository and commit our files to it. We can do so by running the following commands in our project directory: ```console $ git init $ git add . $ git commit -m "Initial commit" ``` Heroku offers some great information on how it is using Git [here](https://devcenter.heroku.com/articles/git#tracking-your-app-in-git). ## Signing up for Heroku Signing up to Heroku is very simple, just head over to [https://signup.heroku.com/](https://signup.heroku.com/) and fill in the form. The Free plan will give us one web [dyno](https://devcenter.heroku.com/articles/dynos#dynos) and one worker dyno, as well as a PostgreSQL and Redis instance for free. These are meant to be used for testing and development, and come with some limitations. In order to run a production application, please consider upgrading to a paid plan. ## Installing the Heroku Toolbelt Once we have signed up, we can download the correct version of the Heroku Toolbelt for our system [here](https://toolbelt.heroku.com/). The Heroku CLI, part of the Toolbelt, is useful to create Heroku applications, list currently running dynos for an existing application, tail logs or run one-off commands (mix tasks for instance). ## Creating the Heroku Application Now that we have the Toolbelt installed, let's create the Heroku application. In our project directory, run: > Note: the first time we use a Heroku command, it may prompt us to log in. If this happens, just enter the email and password you specified during signup. ```console $ heroku create --buildpack "https://github.com/HashNuke/heroku-buildpack-elixir.git" Creating mysterious-meadow-6277... done, stack is cedar-14 Buildpack set. Next release on mysterious-meadow-6277 will use https://github.com/HashNuke/heroku-buildpack-elixir.git. https://mysterious-meadow-6277.herokuapp.com/ | https://git.heroku.com/mysterious-meadow-6277.git Git remote heroku added ``` > Note: the name of the Heroku application is the random string after "Creating" in the output above (mysterious-meadow-6277). This will be unique, so expect to see a different name from "mysterious-meadow-6277". The `--buildpack` option we are passing allows us to specify the [Elixir buildpack](https://github.com/HashNuke/heroku-buildpack-elixir) we want Heroku to use. A [buildpack](https://devcenter.heroku.com/articles/buildpacks) is a convenient way of packaging framework and/or runtime support. In our case it's installing Erlang, Elixir, fetching our application dependencies, and so on, before we run it. The URL in the output is the URL to our application. If we open it in our browser now, we will get the default Heroku welcome page. > Note: if we hadn't initialized our Git repository before we ran the `heroku create` command, we won't have our Heroku remote repository properly set up at this point. We can set that up manually by running: `heroku git:remote -a [our-app-name].` ## Adding the Phoenix Static Buildpack We need to compile static assets for a successful Phoenix deployment. The [Phoenix static buildpack](https://github.com/gjaldon/heroku-buildpack-phoenix-static) can take care of that for us, so let's add it now. ```console $ heroku buildpacks:add https://github.com/gjaldon/heroku-buildpack-phoenix-static.git Buildpack added. Next release on mysterious-meadow-6277 will use: 1. https://github.com/HashNuke/heroku-buildpack-elixir.git 2. https://github.com/gjaldon/heroku-buildpack-phoenix-static.git Run `git push heroku master` to create a new release using these buildpacks. ``` ## Making our Project Heroku-ready Every new Phoenix project ships with a config file `config/prod.secret.exs` which stores configuration that should not be commited along with our source code. By default Phoenix adds it to our `.gitignore` file. This works great except Heroku uses [environment variables](https://devcenter.heroku.com/articles/config-vars) to pass sensitive informations to our application. It means we need to make some changes to our config before we can deploy. First, let's make sure our secret key is loaded from Heroku's environment variables instead of `config/prod.secret.exs` by adding a `secret_key_base` line in `config/prod.exs`: ```elixir config :hello_phoenix, HelloPhoenix.Endpoint, http: [port: {:system, "PORT"}], url: [host: "example.com", port: 80], cache_static_manifest: "priv/static/manifest.json", secret_key_base: System.get_env("SECRET_KEY_BASE") ``` Then, we'll add the production database configuration to `config/prod.exs`: ```elixir # Configure your database config :hello_phoenix, HelloPhoenix.Repo, adapter: Ecto.Adapters.Postgres, url: System.get_env("DATABASE_URL"), pool_size: 20, ssl: true ``` Now, let's tell Phoenix to use our Heroku URL and enforce we only use the SSL version of the website. Find the url line: ```elixir url: [host: "example.com", port: 80], ``` ... and replace it with this (don't forget to replace `mysterious-meadow-6277` with your application name): ```elixir url: [scheme: "https", host: "mysterious-meadow-6277.herokuapp.com", port: 443], force_ssl: [rewrite_on: [:x_forwarded_proto]], ``` Since our configuration is now handled using Heroku's environment variables, we don't need to import the `config/prod.secret.exs` file in `/config/prod.exs` any longer, so we can delete the following line: ```elixir import_config "prod.secret.exs" ``` Our `config/prod.exs` now looks like this: ```elixir use Mix.Config ... config :hello_phoenix, HelloPhoenix.Endpoint, http: [port: {:system, "PORT"}], url: [scheme: "https", host: "mysterious-meadow-6277.herokuapp.com", port: 443], force_ssl: [rewrite_on: [:x_forwarded_proto]], cache_static_manifest: "priv/static/manifest.json", secret_key_base: System.get_env("SECRET_KEY_BASE") # Do not print debug messages in production config :logger, level: :info # Configure your database config :hello_phoenix, HelloPhoenix.Repo, adapter: Ecto.Adapters.Postgres, url: System.get_env("DATABASE_URL"), pool_size: 20, ssl: true ``` Finally, we need to decrease the timeout for the websocket transport in `web/channels/user_socket.ex`: ```elixir defmodule HelloPhoenix.UserSocket do use Phoenix.Socket ... ## Transports transport :websocket, Phoenix.Transports.WebSocket, timeout: 45_000 end ``` This ensures that any idle connections are closed by Phoenix before they reach Heroku's 55 second timeout window. Lastly, we'll need to create a [Procfile](https://devcenter.heroku.com/articles/procfile) with the following: ``` web: MIX_ENV=prod mix phoenix.server ``` ## Creating Environment Variables in Heroku The `DATABASE_URL` config var is automatically created by Heroku when we add the [Heroku Postgres add-on](https://elements.heroku.com/addons/heroku-postgresql). We can create the database via the heroku toolbelt: ```console heroku addons:create heroku-postgresql:hobby-dev ``` We still have to create the `SECRET_KEY_BASE` config based on a random string. First, use `mix phoenix.gen.secret` to get a new secret: ```console $ mix phoenix.gen.secret xvafzY4y01jYuzLm3ecJqo008dVnU3CN4f+MamNd1Zue4pXvfvUjbiXT8akaIF53 ``` Your random string will be different; don't use this example value. Now set it in Heroku: ```console $ heroku config:set SECRET_KEY_BASE="xvafzY4y01jYuzLm3ecJqo008dVnU3CN4f+MamNd1Zue4pXvfvUjbiXT8akaIF53" Setting config vars and restarting mysterious-meadow-6277... done, v3 SECRET_KEY_BASE: xvafzY4y01jYuzLm3ecJqo008dVnU3CN4f+MamNd1Zue4pXvfvUjbiXT8akaIF53 ``` If you need to make any of your config variables available at compile time you will need to explicitly define which ones in a configuration file. Create a file `elixir_buildpack.config` in your applications root directory and add a line like: `config_vars_to_export=(DATABASE_URL MY_VAR)`. See [here](https://github.com/HashNuke/heroku-buildpack-elixir#specifying-config-vars-to-export-at-compile-time) for more information. ## Deploy Time! Our project is now ready to be deployed on Heroku. Let's commit all our changes: ``` $ git add config/prod.exs $ git add Procfile $ git add web/channels/user_socket.ex $ git commit -m "Use production config from Heroku ENV variables and decrease socket timeout" ``` And deploy: ```console $ git push heroku master Counting objects: 55, done. Delta compression using up to 8 threads. Compressing objects: 100% (49/49), done. Writing objects: 100% (55/55), 48.48 KiB | 0 bytes/s, done. Total 55 (delta 1), reused 0 (delta 0) remote: Compressing source files... done. remote: Building source: remote: remote: -----> Multipack app detected remote: -----> Fetching custom git buildpack... done remote: -----> elixir app detected remote: -----> Checking Erlang and Elixir versions remote: WARNING: elixir_buildpack.config wasn't found in the app remote: Using default config from Elixir buildpack remote: Will use the following versions: remote: * Stack cedar-14 remote: * Erlang 17.5 remote: * Elixir 1.0.4 remote: Will export the following config vars: remote: * Config vars DATABASE_URL remote: * MIX_ENV=prod remote: -----> Stack changed, will rebuild remote: -----> Fetching Erlang 17.5 remote: -----> Installing Erlang 17.5 (changed) remote: remote: -----> Fetching Elixir v1.0.4 remote: -----> Installing Elixir v1.0.4 (changed) remote: -----> Installing Hex remote: 2015-07-07 00:04:00 URL:https://s3.amazonaws.com/s3.hex.pm/installs/1.0.0/hex.ez [262010/262010] -> "/app/.mix/archives/hex.ez" [1] remote: * creating /app/.mix/archives/hex.ez remote: -----> Installing rebar remote: * creating /app/.mix/rebar remote: -----> Fetching app dependencies with mix remote: Running dependency resolution remote: Dependency resolution completed successfully remote: [...] remote: -----> Compiling remote: [...] remote: Generated phoenix_heroku app remote: [...] remote: Consolidated protocols written to _build/prod/consolidated remote: -----> Creating .profile.d with env vars remote: -----> Fetching custom git buildpack... done remote: -----> Phoenix app detected remote: remote: -----> Loading configuration and environment remote: Loading config... remote: WARNING: phoenix_static_buildpack.config wasn't found in the app remote: Using default config from Phoenix static buildpack remote: Will use the following versions: remote: * Node 0.12.4 remote: Will export the following config vars: remote: * Config vars DATABASE_URL remote: * MIX_ENV=prod remote: remote: -----> Installing binaries remote: Downloading node 0.12.4... remote: Installing node 0.12.4... remote: Using default npm version remote: remote: -----> Building dependencies remote: [...] remote: Running default compile remote: Building Phoenix static assets remote: 07 Jul 00:06:22 - info: compiled 3 files into 2 files, copied 3 in 3616ms remote: Check your digested files at 'priv/static'. remote: remote: -----> Finalizing build remote: Creating runtime environment remote: remote: -----> Discovering process types remote: Procfile declares types -> (web) remote: Default types for Multipack -> web remote: remote: -----> Compressing... done, 82.1MB remote: -----> Launching... done, v5 remote: https://mysterious-meadow-6277.herokuapp.com/ deployed to Heroku remote: remote: Verifying deploy... done. To https://git.heroku.com/mysterious-meadow-6277.git * [new branch] master -> master ``` Typing `heroku open` in the terminal should launch a browser with the Phoenix welcome page opened. In case you are using Ecto to access a database, you will also need to run migrations after the first deploy: ```console $ heroku run mix ecto.migrate ``` And that's it! ## Useful Heroku Commands We can look at the logs of our application by running the following command in our project directory: ```console $ heroku logs # use --tail if you want to tail them ``` We can also start an IEx session attached to our terminal for experimenting in our app's environment: ```console $ heroku run iex -S mix ``` In fact, we can run anything using the `heroku run` command, like the Ecto migration task from above: ```console $ heroku run mix ecto.migrate ``` ## Troubleshooting ### Compilation Error Occasionally, an application will compile locally, but not on Heroku. The compilation error on Heroku will look something like this: ```console remote: == Compilation error on file lib/postgrex/connection.ex == remote: could not compile dependency :postgrex, "mix compile" failed. You can recompile this dependency with "mix deps.compile postgrex", update it with "mix deps.update postgrex" or clean it with "mix deps.clean postgrex" remote: ** (CompileError) lib/postgrex/connection.ex:207: Postgrex.Connection.__struct__/0 is undefined, cannot expand struct Postgrex.Connection remote: (elixir) src/elixir_map.erl:58: :elixir_map.translate_struct/4 remote: (stdlib) lists.erl:1353: :lists.mapfoldl/3 remote: (stdlib) lists.erl:1354: :lists.mapfoldl/3 remote: remote: remote: ! Push rejected, failed to compile elixir app remote: remote: Verifying deploy... remote: remote: ! Push rejected to mysterious-meadow-6277. remote: To https://git.heroku.com/mysterious-meadow-6277.git ``` This has to do with stale dependencies which are not getting recompiled properly. It's possible to force Heroku to recompile all dependencies on each deploy, which should fix this problem. The way to do it is to add a new file called `elixir_buildpack.config` at the root of the application. The file should contain this line: ``` always_rebuild=true ``` Commit this file to the repository and try to push again to Heroku.