22

We have to use port 80 for our server. But when I was trying to use it in Mac, it always said that the 80 is used, but I don't know which program uses it.

I searched it in Google, and someone said it's about apache, but I tried, which is not working. I found this: https://gist.github.com/kujohn/7209628 , but seems it's not working visiting our server by IP address.

I really don't know what's going on and how can I find out which program using port 80 and stop it.

Many thanks if anyone can help, I'm new using Mac. Thanks.

Sky
  • 5,635
  • 7
  • 25
  • 38
  • possible duplicate of [Who is listening on a given TCP port on Mac OS X?](http://stackoverflow.com/questions/4421633/who-is-listening-on-a-given-tcp-port-on-mac-os-x) – TheDarkKnight Oct 27 '14 at 12:04

6 Answers6

34

To find out what process is using port 80

  1. go to Applications
  2. open utilities.
  3. open Activity Monitor.
  4. click on the Memory tab,
  5. look at the ports and the processes using them. Find port 80 and select it
  6. go to the view on the menu bar and choose Quit process.

This will just kill the process, it will not stop a server instance that is already running from continuing to run. (Correction: the Ports column shows the number of open ports (and files?), not the port number)

It is not clear if you are using a database management system or not and which one but one method that has worked for me using MAMP is as follows.

  • stop the server by using sudo apachectl stop command.
  • then change the port to port 80.
  • then restart your servers.
Seb
  • 24,063
  • 5
  • 57
  • 82
David Odhiambo
  • 539
  • 5
  • 14
  • I went through that whole process. nmap told me 80 was in use and the Activity Monitor said nothing was using port 80.. A simple restart fixed whatever was happening. – Adam F Aug 06 '19 at 15:48
  • as I stated above: It is not clear if you are using a database management system or not and which one but one method that has worked for me using MAMP is as follows. stop the server by using 'sudo apachectl stop' command. then change the port to port 80. then restart your servers. – David Odhiambo Aug 19 '19 at 12:24
15

type the following in Terminal

sudo lsof -i -n -P | grep TCP

you will get a list - e.g. dropbox listens on 80
you can copy the output to a text editor, etc to search

JJD
  • 44,755
  • 49
  • 183
  • 309
  • Thanks. I found this: Google 198 admin 124u IPv4 0x47db4f2daddc29eb 0t0 TCP 172.29.71.138:50854->120.29.145.17:80 (ESTABLISHED) Google 198 admin 126u IPv4 0x47db4f2dadd8addb 0t0 TCP 172.29.71.138:50856->96.17.199.32:80 (ESTABLISHED) Do you know what this means? Seems it's the result of what I did following instruction in the link I provided in my question. But it's not working now. – Sky Oct 29 '14 at 07:33
3

I was having this issue, apache was disabled via launchctl, but was still tying up port 80 after launch, I could start up apache and it would work, but after unloading it, I couldn't start up anything on port 80. I was using the built in web server for Python as an easy test. It would work on port 81, but not on port 80.

sudo python -m SimpleHTTPServer 80 -- wouldn't work

sudo python -m SimpleHTTPServer 81 -- would work

Here are the symptoms:

$ launchctl unload -w /System/Library/LaunchDaemons/org.apache.httpd.plist 
/System/Library/LaunchDaemons/org.apache.httpd.plist: Could not find specified service
$ sudo lsof -i ':80'
COMMAND  PID USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
Python  3353 root    3u  IPv4 0xe455777a82799f05      0t0  TCP *:http (LISTEN)

The fix for me (after way too much searching) was simple:

sudo pfctl -F all

This flushed the packet filter, releasing port 80 (and others I assume 8080, 443, whatever ports apache might be tying up)

After that, and relaunching the python server, it came right up.

Colin
  • 31
  • 1
3

On Mac ports below 1024 can only be bound by the root user. Try launching your server as root user (with sudo), or try to use a port above 1024.

You can also try to add root permissions to your user in /etc/sudoers

# root and users in group wheel can run anything on any machine as any user
root            ALL = (ALL) ALL
%admin          ALL = (ALL) ALL
your_user_here  ALL = (ALL) ALL
Carlos B. Flores
  • 1,485
  • 12
  • 9
  • 3
    That last suggestion of adding root permissions to your own user is very, very dangerous. – grooveplex May 10 '19 at 00:26
  • 1
    Yes, that's true, it's dangerous, for security reasons But as he said, he have a server, and he is only trying to launch it on his Mac, maybe for development purposes, but, it is not recommended to do this permanently, just for trying out purposes. – Carlos B. Flores May 10 '19 at 01:09
  • Yes, I'm using it for development purposes as well so I don't have to reconfigure some API calls. I wouldn't recommend changing the /etc/sudoers file. If it's a temporary development situation, I would just drop to root (```sudo -i```) and then navigate back to the project and run ```serve --port 80```. – Matthew Zackschewski Dec 09 '19 at 20:34
2

Might be Skype that is using port 80. If you have Skype installed and running try to change to a different port in the settings.

Markus Lindberg
  • 147
  • 2
  • 11
  • Thanks for your comment. But I don't have Skype installed yet. – Sky Oct 28 '14 at 01:35
  • Just as what I searched on Google, there's one way changing the listener of one Apache file, which was 80 at the very beginning. But it didn't work after I changed it to other value. – Sky Oct 28 '14 at 01:47
-1

Port numbers in the range from 0 to 1023 are classified as 'well-known' and port number 80 is reserved for HTTP. Typically you have servers listening on port 80 to handle HTTP requests.

Source: http://en.wikipedia.org/wiki/List_of_TCP_and_UDP_port_numbers

Kári
  • 117
  • 3
  • Yeah, but I don't know which one using it. Have any ideas how to find the server using this port? Thank you! – Sky Oct 28 '14 at 01:37
  • Hey, enter the command lsof -n | grep LISTEN in a terminal window to get a list of processes along with the port they're listening on. – Kári Oct 28 '14 at 16:04
  • I got a list, but seems no 80 is used: TCP 127.0.0.1:49563 (LISTEN TCP 127.0.0.1:6942 (LISTEN) TCP 127.0.0.1:63342 (LISTEN TCP *:astromed-main (LISTEN TCP *:49966 (LISTEN) TCP *:49604 (LISTEN) TCP *:ff-sm (LISTEN) TCP *:49607 (LISTEN) TCP *:http-alt (LISTEN) TCP *:8009 (LISTEN) TCP 127.0.0.1:8005 (LISTEN) TCP *:5701 (LISTEN) TCP 127.0.0.1:25035 (LISTEN TCP [::1]:25035 (LISTEN) This is the last column displayed after the command you mentioned. – Sky Nov 11 '14 at 03:03