Mix phx.server has weird output, does not start on port 4000

Going through Phoenix In Action, but using the latest versions of phoenix (1.4.6) and elixir (1.8). In section 6.2, Creating a new Phoenix Application, when I run mix phx.server, I get:

21:10:49.651 [info] Access AuctionWeb.Endpoint at http://localhost

The port is truncated at the end and no mention of Cowboy. This seems to be wrong compared to output I have seen around the internet. What am I doing wrong?

The output depends on your endpoint configuration. Could you please tell us what your config/dev.exs does to configure your endpoint?

Sure!

use Mix.Config

# For development, we disable any cache and enable
# debugging and code reloading.
#
# The watchers configuration can be used to run external
# watchers to your application. For example, we use it
# with webpack to recompile .js and .css sources.
config :auction_web, AuctionWeb.Endpoint,
  http: [port: 4000],
  debug_errors: true,
  code_reloader: true,
  check_origin: false,
  watchers: [
    node: [
      "node_modules/webpack/bin/webpack.js",
      "--mode",
      "development",
      "--watch-stdin",
      cd: Path.expand("../apps/auction_web/assets", __DIR__)
    ]
  ]

# ## SSL Support
#
# In order to use HTTPS in development, a self-signed
# certificate can be generated by running the following
# Mix task:
#
#     mix phx.gen.cert
#
# Note that this task requires Erlang/OTP 20 or later.
# Run `mix help phx.gen.cert` for more information.
#
# The `http:` config above can be replaced with:
#
#     https: [
#       port: 4001,
#       cipher_suite: :strong,
#       keyfile: "priv/cert/selfsigned_key.pem",
#       certfile: "priv/cert/selfsigned.pem"
#     ],
#
# If desired, both `http:` and `https:` keys can be
# configured to run both http and https servers on
# different ports.

# Watch static and templates for browser reloading.
config :auction_web, AuctionWeb.Endpoint,
  live_reload: [
    patterns: [
      ~r"priv/static/.*(js|css|png|jpeg|jpg|gif|svg)$",
      ~r"priv/gettext/.*(po)$",
      ~r"lib/auction_web/{live,views}/.*(ex)$",
      ~r"lib/auction_web/templates/.*(eex)$"
    ]
  ]

# For development, we disable any cache and enable
# debugging and code reloading.
#
# The watchers configuration can be used to run external
# watchers to your application. For example, we use it
# with webpack to recompile .js and .css sources.
config :auction_web, AuctionWeb.Endpoint,
  http: [port: 4000],
  debug_errors: true,
  code_reloader: true,
  check_origin: false,
  watchers: [
    node: [
      "node_modules/webpack/bin/webpack.js",
      "--mode",
      "development",
      "--watch-stdin",
      cd: Path.expand("../apps/auction_web/assets", __DIR__)
    ]
  ]

# ## SSL Support
#
# In order to use HTTPS in development, a self-signed
# certificate can be generated by running the following
# Mix task:
#
#     mix phx.gen.cert
#
# Note that this task requires Erlang/OTP 20 or later.
# Run `mix help phx.gen.cert` for more information.
#
# The `http:` config above can be replaced with:
#
#     https: [
#       port: 4001,
#       cipher_suite: :strong,
#       keyfile: "priv/cert/selfsigned_key.pem",
#       certfile: "priv/cert/selfsigned.pem"
#     ],
#
# If desired, both `http:` and `https:` keys can be
# configured to run both http and https servers on
# different ports.

# Watch static and templates for browser reloading.
config :auction_web, AuctionWeb.Endpoint,
  live_reload: [
    patterns: [
      ~r"priv/static/.*(js|css|png|jpeg|jpg|gif|svg)$",
      ~r"priv/gettext/.*(po)$",
      ~r"lib/auction_web/{live,views}/.*(ex)$",
      ~r"lib/auction_web/templates/.*(eex)$"
    ]
  ]

Note that I when I created the phoenix project with mix phx.new instead of mix phix.new.web the dev server boots appropriately https://github.com/PhoenixInAction/phoenix-in-action/issues/3.

:wave:

mix phx.new.web is to generate a phoenix app inside an umbrella project, it probably won’t work outside of an umbrella (configs, build, deps paths would be wrong probably). mix phx.new generates a standalone app.

1 Like

:wave: :wave:

Right! That was my understanding. The book I’m going through had me create a new Phoenix project in a umbrella app. I created it in /apps, adjacent to another app that holds the business logic and repo communication.

Is it possible (if the code from the book is not copyrighted) to post the umbrella project with mix phx.new.web generated app to github (the one that doesn’t work)?

How could I check if it’s copyrighted or not?

Depends on the jurisdiction of the author, but most assume implicit copyright unless stated otherwise as far as I know.

I see. All of the code is posted on GitHub so I’d assume me recreating it with different dependency versions wouldn’t violate anything.

Working through same book, having same problem.

Elixir 1.8.1
Phoenix v1.4.6

Is mix phx.new.web supposed to generate its own /config directory? If so, it’s missing. Or does it rely on the config from the umbrella?

1 Like

With Elixir 1.8.1 and Phoenix v1.4.6

$ mix phx.new.web auction_web --no-ecto

Is producing a ../apps/auction_web/ directory with no /config:

.gitignore
README.md
assets
lib
mix.exs
priv
test

But looking at the github repository for the book ( https://github.com/PhoenixInAction/phoenix-in-action/tree/master/ch06/auction_umbrella/apps/auction_web ) it looks like it is supposed to be there.

Downgraded to phx 1.4.2 (which is used in the book), deleted ../apps/auction_web/ then ran $ mix phx.new.web auction_web --no-ecto again.

Now there is a ../apps/auction_web/config directory and mix phx.server works as expected and is using port 4000.

$ mix phx.server

14:47:07.837 [info] Running AuctionWeb.Endpoint with cowboy 2.6.3 at 0.0.0.0:4000 (http)

14:47:07.845 [info] Access AuctionWeb.Endpoint at http://localhost:4000

Did something change or break between 1.4.2 and 1.4.6?

@furoshiki good find! Seems that Lessel is on the case as well https://github.com/PhoenixInAction/phoenix-in-action/issues/3#issuecomment-498290156.

1 Like

AFAIK <app>/config directories are being removed from mix new helpers by default (in elixir v1.9, phoenix’s helpers might be a bit ahead of time) so as not to confuse the users (since mix config is evaluated at compile time, not runtime). <-- Absolutely not relevant, sorry.

This might be more relevant however --> https://github.com/phoenixframework/phoenix/issues/3429

2 Likes

Looks like there is a fix merged into master for phoenix: https://github.com/PhoenixInAction/phoenix-in-action/issues/3#issuecomment-498575667

1 Like

Hi! I saw this this morning. Thanks for the r(port.

Yeah, it looks like this was a little hiccup with Phoenix. Hopefully they’ll release the new generators soon.

In the future, feel free to @geo me if you need anything else.

3 Likes