Skip to content

Commit

Permalink
Updates the deploy guide to what worked with Phoenix and Liveview as … (
Browse files Browse the repository at this point in the history
#5558)

* Updates the deploy guide to what worked with Phoenix and Liveview as of today

* Use PHX_HOST in Heroku guide instead of using prod.exs

---------

Co-authored-by: Pickell, Todd <tpickell@estee.com>
Co-authored-by: Gary Rennie <gazler@gmail.com>
  • Loading branch information
3 people authored Sep 12, 2023
1 parent 0a7cef3 commit 5ebc69f
Showing 1 changed file with 25 additions and 6 deletions.
31 changes: 25 additions & 6 deletions guides/deployment/heroku.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,19 +152,32 @@ Finally, note that since we are using multiple buildpacks, you might run into an

Every new Phoenix project ships with a config file `config/runtime.exs` (formerly `config/prod.secret.exs`) which loads configuration and secrets from [environment variables](https://devcenter.heroku.com/articles/config-vars). This aligns well with Heroku best practices, so the only work left for us to do is to configure URLs and SSL.

First let's tell Phoenix to use our Heroku URL and enforce we only use the SSL version of the website. Also, bind to the port requested by Heroku in the [`$PORT` environment variable](https://devcenter.heroku.com/articles/runtime-principles#web-servers). Find the url line in your `config/prod.exs`:
First let's tell Phoenix enforce we only use the SSL version of the website. Find the endpoint config in your `config/runtime.exs`:

```elixir
url: [host: "example.com", port: 80],
config :scaffold, ScaffoldWeb.Endpoint,
url: [host: host, port: 443, scheme: "https"],
```

... and replace it with this (don't forget to replace `mysterious-meadow-6277` with your application name):
... and add `force_ssl`

```elixir
url: [scheme: "https", host: "mysterious-meadow-6277.herokuapp.com", port: 443],
force_ssl: [rewrite_on: [:x_forwarded_proto]],
config :scaffold, ScaffoldWeb.Endpoint,
url: [host: host, port: 443, scheme: "https"],
force_ssl: [rewrite_on: [:x_forwarded_proto]],
```

Then in your `config/runtime.exs` (formerly `config/prod.secret.exs`) and uncomment the `# ssl: true,` line in your repository configuration. It will look like this:

```elixir
config :hello, Hello.Repo,
ssl: true,
url: database_url,
pool_size: String.to_integer(System.get_env("POOL_SIZE") || "10")
```



Then open up your `config/runtime.exs` (formerly `config/prod.secret.exs`) and uncomment the `# ssl: true,` line in your repository configuration. It will look like this:

```elixir
Expand All @@ -187,6 +200,12 @@ defmodule HelloWeb.Endpoint do
end
```

Also set the host in Heroku:

```console
$ heroku config:set PHX_HOST="mysterious-meadow-6277.herokuapp.com"
```

This ensures that any idle connections are closed by Phoenix before they reach Heroku's 55-second timeout window.

## Creating Environment Variables in Heroku
Expand Down Expand Up @@ -244,7 +263,7 @@ $ git commit -a -m "Use production config from Heroku ENV variables and decrease
And deploy:

```console
$ git push heroku master
$ git push heroku main
Counting objects: 55, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (49/49), done.
Expand Down

0 comments on commit 5ebc69f

Please sign in to comment.