3

I have apache2 installed on Mac OS X 10.7.4 via macports

Recently I have not been able to access my localhost directory I get a 404, but I can access 127.0.0.1

I've tried restarting apache:

sudo /opt/local/apache2/bin/apachectl stop
sudo /opt/local/apache2/bin/apachectl start

and I get the following errors:

(48)Address already in use: make_sock: could not bind to address [::]:80
(48)Address already in use: make_sock: could not bind to address [::]:443

I've checked that web sharing is off. It seems like apache is already using these points or the service is not stopping correctly.

How can I find out what is using the ports?

3 Answers 3

2

The "lsof" shell command can tell you exactly which process is using which files and socket addresses in the system. Just try a

sudo lsof

or, since the output will be a lot, better

sudo lsof | less

and look for something on the http ports. As usual

man lsof

will give you more information on how to customise the output.

3
  • Thanks lsof -i :80 shows processes using that port. Any idea how to fix the Apache errors?
    – benedict_w
    Sep 24, 2012 at 9:23
  • Well, the only way to let Apache bind to those ports is by getting rid of the processes that are using them, try the 'kill' shell command...
    – Seg Fault
    Sep 24, 2012 at 9:26
  • It seems that the mac version of apache has started /usr/sbin/httpd even though I have "web sharing" turned off. If I kill this process it restarts, even though it's disabled in the launch daemons. This seems to be what is stopping the macports apache running.
    – benedict_w
    Sep 24, 2012 at 9:47
3

For reference, in Mountain Lion 10.8.2, simply stopping the apache2 service did the trick:

sudo apachectl stop

That way the httpd processes won't restart, and the Macports apache2 server will start fine after that.

0

In my Mac with Mojave (10.14.1), suddenly Apache couldn't serve IPv4 anymore, then gave me ERROR 403.  I tried to kill all apache (sudo killall httpd)... checking the PID's with

sudo lsof | grep AMP | grep apache

even didn't work... just IPv6 was available... still ERROR 403

What works for me: disable macOS’s built-in Apache server.

sudo launchctl unload -w /System/Library/LaunchDaemons/org.apache.httpd.plist

after that:

sudo apachectl -k restart

be happy :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.