Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Start Phoenix app with cowboy server on different port

Is it possible to start locally a few Phoenix apps on different ports from the console using some command like mix phoenix.server --port=4001? This one does not work, of course, but, maybe, there is similar way.

like image 217
kovpack Avatar asked May 29 '15 23:05

kovpack


3 Answers

Yep! Make sure you set the mix config to reference the env port, i.e.

config :my_app, MyApp.Endpoint,
  http: [port: {:system, "PORT"}],

Then from the terminal:

$ PORT=4001 mix phoenix.server
$ PORT=4002 mix phoenix.server
$ PORT=4003 mix phoenix.server
like image 198
Chris McCord Avatar answered Nov 06 '22 05:11

Chris McCord


Edit your config/dev.exs and change the Endpoint http port like the following:

config :my_app, MyApp.Endpoint,
  http: [port: System.get_env("PORT") || 4000],

This allows the port to be set, or left as the default 4000:

PORT=4002 mix phoenix.server # to run on port 4002
mix phoenix.server # to run on port 4000

This answer was described by @chris-mccord on github.

like image 40
steakunderscore Avatar answered Nov 06 '22 05:11

steakunderscore


This was needed for me as a solution since my issue was that I needed to let C9.io dictate the port, for me, adding this code to the dev.exs file solved the problem:

config :my_app, MyApp.Endpoint,
  http: [port: {:system, "PORT"}],

and then in the Terminal, I just needed to run the server as normal:

mix phoenix.server
like image 2
Jason Rueckert Avatar answered Nov 06 '22 07:11

Jason Rueckert