My OS is macOS 12.5.1. I use Apache for local testing before uploading my files to the public web server.
If I open a web browser to localhost, it finds the "It works!" page as expected. However if I run apachectl, it thinks it isn't running:
(48)Address already in use: AH00072: make_sock: could not bind to address [::]:80
(48)Address already in use: AH00072: make_sock: could not bind to address 0.0.0.0:80
no listening sockets available, shutting down
AH00015: Unable to open logs
Looking for Other Running Web Servers
Some people have this problem because another web server process is already listening on that port. I check what is listening on port 80 with sudo lsof -i:80. Nothing but httpd is there... but there are two processes of it, one with USER root and the other with USER _www:
httpd 7545 root 4u IPv6 0x23bf089a63ab4185 0t0 TCP *:http (LISTEN)
httpd 7558 _www 4u IPv6 0x23bf089a63ab4185 0t0 TCP *:http (LISTEN)
If I stop Apache with sudo apachectl stop, then sudo lsof -i:80 returns no output. So it appears that no other server is installed and running, but I may have two different httpd processes both trying to listen (and write logs).
If I refresh my browser session a few times, it spawns some more of the ones with USER _www:
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
firefox 1470 [me] 195u IPv4 0x23bf089a63d3d63d 0t0 TCP localhost:52572->localhost:http (ESTABLISHED)
httpd 7805 root 4u IPv6 0x23bf089a63ab2585 0t0 TCP *:http (LISTEN)
httpd 7809 _www 4u IPv6 0x23bf089a63ab2585 0t0 TCP *:http (LISTEN)
httpd 7810 _www 4u IPv6 0x23bf089a63ab2585 0t0 TCP *:http (LISTEN)
httpd 7811 _www 4u IPv6 0x23bf089a63ab2585 0t0 TCP *:http (LISTEN)
httpd 7811 _www 11u IPv6 0x23bf089a63ab4185 0t0 TCP localhost:http->localhost:52572 (ESTABLISHED)
httpd 7812 _www 4u IPv6 0x23bf089a63ab2585 0t0 TCP *:http (LISTEN)
httpd 7813 _www 4u IPv6 0x23bf089a63ab2585 0t0 TCP *:http (LISTEN)
httpd 7822 _www 4u IPv6 0x23bf089a63ab2585 0t0 TCP *:http (LISTEN)
Looking for Multiple Listen Statements in httpd.conf
Some people get this error because their httpd.conf file contains multiple Listen statements. These are the only ones in mine:
<IfDefine SERVER_APP_HAS_DEFAULT_PORTS>
Listen 8080
</IfDefine>
<IfDefine !SERVER_APP_HAS_DEFAULT_PORTS>
Listen 80
</IfDefine>
Within httpd.conf there are some Include statements for other .conf files. However, the only one that contains a Listen statement is httpd-ssl.conf:
Listen 443
Just to be sure, I commented out every Include statement in httpd.conf and ran sudo apachectl restart. apachectl continues to report the error. Browsing to localhost continues to work.
Then to be sure, I changed the Listen 80 statement to the arbitrarily chosen Listen 31637 and ran sudo apachectl restart. apachectl now reported it was having trouble listening on that port:
(48)Address already in use: AH00072: make_sock: could not bind to address [::]:31637
(48)Address already in use: AH00072: make_sock: could not bind to address 0.0.0.0:31637
no listening sockets available, shutting down
AH00015: Unable to open logs
About those Processes with Users root and _www
So I don't think I have any other web servers, and I don't think I have any duplicate Listen statements spread across my .conf files. My best guess at this point is that two or more processes of httpd are trying to run with the same settings, and failing because they are trying to listen to the same port. My httpd.conf also contains this:
# If you wish httpd to run as a different user or group, you must run
# httpd as root initially and it will switch.
#
# User/Group: The name (or #number) of the user/group to run httpd as.
# It is usually good practice to create a dedicated user and group for
# running httpd, as with most system services.
#
User _www
Group _www
So having one start as root and the others start as _www is expected behavior. But should the one as root continue running, or is that a possible source of this problem?