1

I know we can launch iex -S mix phoenix.server. But say I am already in iex -S mix. What can I do to get the server started?

Thank you.

3 Answers3

3

It's maybe not a great way of doing it, but I'm imagining you're only doing this in dev anyway. But one way of doing it would be to set the same config option mix phx.server sets then restarting your endpoint (this example stops it and lets the app supervisor restart it).

iex> Application.put_env(:phoenix, :serve_endpoints, true)
:ok
iex> GenServer.stop(MyAppWeb.Endpoint)
:ok
[info] Running MyAppWeb.Endpoint with cowboy 2.9.0 at 0.0.0.0:4000 (http)
Brett Beatty
  • 5,690
  • 1
  • 23
  • 37
  • The only answer that understood the issue and directly addressed it with understanding! I tested it and it works. Thank you @BrettBeatty. – user3066199 Jun 13 '21 at 17:24
2

Just start running as iex -S mix phx.server, then both iex and your application will run together

Sabit Rakhim
  • 460
  • 3
  • 12
  • This doesn't answer the question. Sometimes I already have stuff set up in iex and I don't want to restart. Perhaps I should have been clearer. – user3066199 Jun 13 '21 at 17:25
-2

I'm sorry to tell you that this cannot be done.

See this discussion for reference: https://elixirforum.com/t/mix-task-run-deps-compile-dep-name-force-not-compiling/12114/4

I quote:

Mix is not intended to be called from iex or inside of your application. The primary interface is the CLI and because of this tasks are allowed to only run once.

Peaceful James
  • 1,807
  • 1
  • 7
  • 16
  • I tried Brett's solution and it works. If you disagree, or think it is incomplete, please let us know. Thank you Peaceful James for your effort in answering. – user3066199 Jun 13 '21 at 17:27