Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OSX: Failed to listen on localhost:80 (reason: Permission denied)

Tags:

php

port

phpstorm

I have downloaded PhpStorm and set all the required configuration. When I try to run the project on port 80, I get this error.

Failed to listen on localhost:80 (reason: Permission denied)

And when I try to use any other ports like 8080 ,I get this error.

Failed to listen on localhost:8080 (reason: Address already in use)

I have tried several different random ports. But I get this already in use error all the time.

I have xampp installed. And when I try to run the url in browser with port , it works fine. The problem is that it isn't working on PhpStorm.

I am stuck.

like image 818
hellosheikh Avatar asked Jan 02 '16 08:01

hellosheikh


2 Answers

The PHPStorm / Intellij built-in web server listens on port 63342 by default.

https://confluence.jetbrains.com/display/PhpStorm/Using+the+Built-in+Webserver+in+PhpStorm

You can set the port in the Run/Debug Configurations under PHP Built-in Web Server:

enter image description here

like image 152
Peter Gluck Avatar answered Sep 22 '22 21:09

Peter Gluck


The errors description are very clear:

The error:

Failed to listen on localhost:80 (reason: Permission denied)

  • You really don't have permission to use this port; so you need to change your user or use sudo to run your application.

and the error:

Failed to listen on localhost:8080 (reason: Address already in use)

  • The address that you are trying to use localhost:8080 is already in use by other processes/software.

Normally, if you change the port will solve the problem: (eg. 9090).


But, if you want to know which program is using the port 80 in Unix (Mac OSX, Linux), you can use the lsof command:

To do this:

In the terminal, you need to use:

sudo lsof -i :80

That will result something like this:

COMMAND    PID   USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
httpd       82   root    4u  IPv6 0x763617bed21ecc33      0t0  TCP *:http (LISTEN)
httpd      226   _www    4u  IPv6 0x763617bed21ecc33      0t0  TCP *:http (LISTEN)

On this result, we can see that the /usr/sbin/httpd is listening on port 80 on my machine, which is the Apache server.

To know the details of the process that is listening on port 80 you can use the ps command:

ps u  PID_of_target_process

that will return a result similar to this:

USER   PID  %CPU %MEM      VSZ    RSS   TT  STAT STARTED      TIME COMMAND
root    82   0.0  0.0  2463324   4248   ??  Ss    9:48AM   0:00.93 /usr/sbin/httpd -D FOREGROUND

To kill the process by the PID you can use the kill command, like the following:

sudo kill -KILL PID_of_target_process

After you kill the process the port will be available again.

like image 32
valdeci Avatar answered Sep 21 '22 21:09

valdeci