Introduction

Phoenix is an awesome new web framework based on the Elixir language. It’s overarching goal is to allow developers to productively build scalable web applications.

As the framework has not had its first major release yet, it expectedly includes significant changes from version to version. To make life easier for us, the team is doing an awesome job of creating little “How-To Upgrade” guides that are published on their website. Here’s an example for upgrading from v0.10 to v0.11.

Up and Running

Getting everything set up is a breeze. Jump on over to the docs that have a complete outline of required steps.

Setting up for Heroku

Even though we only have a barebone app right now, let’s go ahead and deploy it to Heroku.

If this is your first time deploying to Heroku, you’ll need to create an account and downland and install the heroku toolbelt.

Once we’ve got that done, make sure you’re in your Phoenix project’s directory and create an empty git repository,

$ git init

and create a new heroku application.

$ heroku create

Next, we need to tell Heroku to utilize a custom buildpack because there is no official Elixir buildpack yet.

$ heroku buildpack:set https://github.com/HashNuke/heroku-buildpack-elixir.git

And we’ll set our Mix environment to production.

$ heroku config:set MIX_ENV=prod

Heroku requires a Procfile. A Procfile is executed when a dyno of the associated process type is started and includes tasks such as starting the server. For this let’s create a file called Procfile in the root folder of your application, with the following content.

web: yes | mix compile.protocols && elixir -pa _build/prod/consolidated -S mix phoenix.server

Final adjustments

Finally, in order for our assets to be available on Heroku, we will need to comment out the last two lines in our .gitignore file.

# Mix artifacts
/_build
/deps
/*.ez

# Generate on crash by the VM
erl_crash.dump

# Static artifacts
/node_modules

# Since we are building js and css from web/static,
# we ignore priv/static/{css,js}. You may want to
# comment this depending on your deployment strategy.
# /priv/static/css
# /priv/static/js

Phoenix automatically compiles assets from your /web/static/ directory into /priv/static/ when the server is running. If they were gitignored, the compiled assets would not be available on Heroku. With the coming v0.12 release, they will no longer be gitignored by default.

Push

And we’re done. Let’s add it all to our git repository, commit it and push it up to Heroku.

$ git add --all
$ git commit -m "initial commit"
$ git push heroku master