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
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
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)"
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