New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default (4000) port busy #962

Closed
wafcio opened this Issue Jun 12, 2015 · 22 comments

Comments

Projects
None yet
9 participants
@wafcio
Copy link

wafcio commented Jun 12, 2015

I am using OS X and I have tried (many time with computer restarts) to run phoenix server on port 4000 and each time I receive information:

[error] Running PhoenixJobs.Endpoint with Cowboy on port 4000 (http) failed, port already in use

=INFO REPORT==== 13-Jun-2015::00:35:13 ===
    application: logger
    exited: stopped
    type: temporary
** (Mix) Could not start application phoenix_jobs: PhoenixJobs.start(:normal, []) returned an error: shutdown: failed to start child: PhoenixJobs.Endpoint
    ** (EXIT) shutdown: failed to start child: Phoenix.Endpoint.Server
        ** (EXIT) shutdown: failed to start child: :http
            ** (EXIT) shutdown: failed to start child: :ranch_acceptors_sup
                ** (EXIT) an exception was raised:
                    ** (MatchError) no match of right hand side value: {:error, :eaddrinuse}
                        (ranch) src/ranch_acceptors_sup.erl:30: :ranch_acceptors_sup.init/1
                        (stdlib) supervisor.erl:243: :supervisor.init/1
                        (stdlib) gen_server.erl:306: :gen_server.init_it/6
                        (stdlib) proc_lib.erl:237: :proc_lib.init_p_do_apply/3

Port 4000 isn't busy because in other time I can use this port to run other apps (in different language).

I am using the latest phoenix framework version and Elixir 1.0.4.

Maybe you can add support to OPTIONAL port numer in config (for development environment). When I changed config and pass port 4001, application have started without problems.

@wafcio wafcio changed the title Default port busy Default (4000) port busy Jun 12, 2015

@chrismccord

This comment has been minimized.

Copy link
Member

chrismccord commented Jun 12, 2015

As a sanity check, can you change the port in dev.exs to something else, say 4004 and see if it works?

@wafcio

This comment has been minimized.

Copy link
Author

wafcio commented Jun 12, 2015

Of course I can and I did. But I think it will be better to pass port number in terminal. I think this way is more obvious for new people outside elixir ecosystem. If you agree thats nice, if you don't agree thats ok.

@chrismccord

This comment has been minimized.

Copy link
Member

chrismccord commented Jun 12, 2015

So something must be taking up port 4000 on your system. To achieve what you want, you can simply default to System.get_env("PORT") in dev.exs:

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

This comment has been minimized.

Copy link
Member

chrismccord commented Jun 12, 2015

The you can dynamically set the port with:

$ PORT=4004 mix phoenix.server
@wafcio

This comment has been minimized.

Copy link
Author

wafcio commented Jun 12, 2015

thanks a lot

@bcs2002

This comment has been minimized.

Copy link

bcs2002 commented Jul 21, 2015

The you can dynamically set the port with:
$ PORT=4004 mix phoenix.server

How do you give this command in Windows?

@josevalim

This comment has been minimized.

Copy link
Member

josevalim commented Jul 22, 2015

I think it is:

set /a "PORT=4004" && mix phoenix.server
@bcs2002

This comment has been minimized.

Copy link

bcs2002 commented Jul 24, 2015

Thanks Jose.

@Radhika-Adoni

This comment has been minimized.

Copy link

Radhika-Adoni commented Aug 24, 2016

Tried all the options above and changed the port number in dev file. But the terminal is getting hung while executing mix phoenix.server

mix phoenix.server
Compiling 12 files (.ex)
Generated app app
[info] Running App.Endpoint with Cowboy using http://localhost:4004
24 Aug 17:38:00 - info: compiled 6 files into 2 files, copied 3 in 1 sec

The below is my mix.exs file.

defmodule App.Mixfile do
use Mix.Project

def project do
[app: :app,
version: "0.0.1",
elixir: "~> 1.2",
elixirc_paths: elixirc_paths(Mix.env),
compilers: [:phoenix, :gettext] ++ Mix.compilers,
build_embedded: Mix.env == :prod,
start_permanent: Mix.env == :prod,
aliases: aliases(),
deps: deps()]
end

Configuration for the OTP application.

Type mix help compile.app for more information.

def application do
[mod: {App, []},
applications: [:phoenix, :phoenix_pubsub, :phoenix_html, :cowboy, :logger, :gettext,
:phoenix_ecto, :postgrex]]
end

Specifies which paths to compile per environment.

defp elixirc_paths(:test), do: ["lib", "web", "test/support"]
defp elixirc_paths(_), do: ["lib", "web"]

Specifies your project dependencies.

Type mix help deps for examples and options.

defp deps do
[{:phoenix, "> 1.2.1"},
{:phoenix_pubsub, "
> 1.0"},
{:phoenix_ecto, "> 3.0"},
{:postgrex, ">= 0.0.0"},
{:phoenix_html, "
> 2.6"},
{:phoenix_live_reload, "> 1.0", only: :dev},
{:gettext, "
> 0.11"},
{:cowboy, "~> 1.0"}]
end

@chrismccord

This comment has been minimized.

Copy link
Member

chrismccord commented Aug 24, 2016

@Radhika-Adoni everything looks fine. Is the app accessible at the port you are using? If you were wanting an iex prompt, you need to run with iex -S mix phoenix.server

@Radhika-Adoni

This comment has been minimized.

Copy link

Radhika-Adoni commented Aug 24, 2016

Used this command..and the issue got resolved :)

MIX_ENV=prod PORT=80 iex -S mix phoenix.server..used port 80..

@Radhika-Adoni

This comment has been minimized.

Copy link

Radhika-Adoni commented Aug 24, 2016

Its one week into Elixir and my first Functional Programming language and I am loving it..

@Radhika-Adoni

This comment has been minimized.

Copy link

Radhika-Adoni commented Aug 29, 2016

Hello Chris

The command is working for prod environment but for dev mix phoenix.server is still getting hung.

@josevalim

This comment has been minimized.

Copy link
Member

josevalim commented Aug 29, 2016

You can use something like lsof -i :4000 to find out which process is listening on this port and then try to find more information about it. See this article for examples: http://www.cyberciti.biz/faq/what-process-has-open-linux-port/ (there is a section about lsof at the end).

@nerimartinez

This comment has been minimized.

Copy link
Contributor

nerimartinez commented Nov 25, 2016

or you can just do killall beam.smp

@OvermindDL1

This comment has been minimized.

Copy link
Contributor

OvermindDL1 commented Nov 26, 2016

or you can just do killall beam.smp

That only works if it is a beam program that has port 4000, in addition it will kill all other beam programs as well, and it only works on *nix-like OS's (and even then not all as technically killall is nonstandard).

@mm-tfx

This comment has been minimized.

Copy link

mm-tfx commented Jan 30, 2017

I am missing something probably but I cannot make it work.
In dev.exs:
http: [port: System.get_env("PORT") || 8081]

Then tries: $ PORT=5688 mix phoenix.server and Cowboy starts on port 4000.

Running: PORT=8085 iex -S mix phoenix.server Cowboy still starts on port 4000 but
iex(2)> System.get_env "PORT"
"8085"

How can I define default port to 8081 while make it still possible to configure it from command line?
Thanks.

@chrismccord

This comment has been minimized.

Copy link
Member

chrismccord commented Jan 30, 2017

You most likely did not configure the http: [port: System.get_env("PORT") || 8081] for the dev env. Are you sure you made those changes in config/dev.exs ?

@mm-tfx

This comment has been minimized.

Copy link

mm-tfx commented Jan 30, 2017

I am sure and I think I have found the answer.
Just to double check: what will happen when I would call http: [] twice?
The second call will override the first one, right?

@chrismccord

This comment has been minimized.

Copy link
Member

chrismccord commented Jan 30, 2017

yes

@chrismccord

This comment has been minimized.

Copy link
Member

chrismccord commented Jan 30, 2017

To be clear, the 2nd one, in a separate mix config would be merged with the prior one

@rolfb

This comment has been minimized.

Copy link

rolfb commented Mar 23, 2017

May be helpful for people finding this later.

Running sudo lsof -i :4000 will give you the list of processes using the default port which you can further inspect in Activity Monitor.

In my particular case it was a NoMachine (nx) service running there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment