Skip to content

Instantly share code, notes, and snippets.

@TurplePurtle
Last active December 21, 2015 21:12
Show Gist options
  • Save TurplePurtle/8abc4f8885ba1fe65877 to your computer and use it in GitHub Desktop.
Save TurplePurtle/8abc4f8885ba1fe65877 to your computer and use it in GitHub Desktop.
Cheat sheet for starting a new Phoenix 1.1 project.

Up And Running

Refer to http://www.phoenixframework.org/docs/installation for installing Phoenix and dependencies.

mix phoenix.new hello_phoenix

# ...

Fetch and install dependencies? [Yn] y

# ...

cd hello_phoenix

Or manually install dependencies:

Fetch and install dependencies? [Yn] n

$ cd hello_phoenix
$ mix deps.get
$ mix ecto.create
$ mix phoenix.server

$ npm install

Create DB with

mix ecto.create

Start server with

mix phoenix.server

Deploying on Heroku

Creating repo and Heroku app

Initialize git

git init .
git add .
git commit -m "First commit"

Create app with Elixir buildpack:

heroku create -b "https://github.com/HashNuke/heroku-buildpack-elixir.git"

Add Phoenix buildpack:

heroku buildpacks:add https://github.com/gjaldon/heroku-buildpack-phoenix-static.git

Making Phoenix App Ready For Heroku

Set host, force ssl, set secret_key_base from env, configure database.

Assuming app is called HelloPhoenix, in config/prod.exs:

# ...
  config :hello_phoenix, HelloPhoenix.Endpoint,
    http: [port: {:system, "PORT"}],
-   url: [host: "example.com", port: 80],
-   cache_static_manifest: "priv/static/manifest.json"
+   url: [scheme: "https", host: "hellophoenix.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 the database
+ config :hello_phoenix, HelloPhoenix.Repo,
+   adapter: Ecto.Adapters.Postgres,
+   url: System.get_env("DATABASE_URL"),
+   pool_size: 20

- import_config "prod.secret.exs"

Create and set the SECRET_KEY_BASE env var:

heroku config:set SECRET_KEY_BASE="$(mix phoenix.gen.secret)"

Deploy Time!

Commit and push:

git add config/prod.exs
git commit -m "Use production config from Heroku ENV variables"
git push heroku master

Run migration if using Ecto necessary:

heroku run mix ecto.migrate

Can start an IEx session on remote app:

heroku run iex -S mix
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment