4

I can't seem to get Apache to start on any port. I'm always getting the error:

apache2(98)Address already in use: AH00072: make_sock: could not bind to address [::]:80

I checked to make sure that nothing is running on port 80 with netstat -plant|grep 80 and I even ran sudo nc -l 80 with no problems just to be certain. I thought maybe it might be a permissions thing (it shouldn't since it should be starting from an initscript), so I changed the listening port for Apache to 8080, and got the same error except on port 8080 (and nothing is running on that port either). I even tried setting ports.conf to have Listen 127.0.0.1:80 and even Listen 127.0.0.1:8080 and still more or less the same error except for showing the corresponding address and port.

I should note that I'm on Debian Unstable.

At this point, I'm at a loss for what else to check.

10
  • 2
    Check if SELinux or something similar is on, by runnning sestatus or getenforce. Jul 18, 2013 at 4:27
  • root@debian:/home/mohsen/Downloads# netstat -atupn |egrep :80 |egrep LISTEN tcp6 0 0 :::80 :::* LISTEN 5261/apache2 Jul 18, 2013 at 5:03
  • or nmap localhost Jul 18, 2013 at 5:04
  • I don't have SELinux on this machine, so that shouldn't be an issue. That netstat command returns nothing. And nmap doesn't show port 80 as even being open. Jul 18, 2013 at 5:48
  • I wonder what your Apache startup script looks like? Can you post it? Let's just say for the sake of the argument that the script happened to have a bug that would start httpd twice ? Aug 5, 2013 at 12:53

3 Answers 3

6
+50

From your strace file, here is your problem:

[pid 23020] setsockopt(5, SOL_SOCKET, SO_REUSEADDR, [1], 4) = 0
[pid 23020] setsockopt(5, SOL_SOCKET, SO_KEEPALIVE, [1], 4) = 0
[pid 23020] setsockopt(5, SOL_IPV6, IPV6_V6ONLY, [0], 4) = 0
[pid 23020] setsockopt(5, SOL_TCP, TCP_NODELAY, [1], 4) = 0
[pid 23020] bind(5, {sa_family=AF_INET6, sin6_port=htons(80), inet_pton(AF_INET6, "::", &sin6_addr), sin6_flowinfo=0, sin6_scope_id=0}, 28) = 0
[pid 23020] listen(5, 511)              = 0
[pid 23020] setsockopt(7, SOL_SOCKET, SO_REUSEADDR, [1], 4) = 0
[pid 23020] setsockopt(7, SOL_SOCKET, SO_KEEPALIVE, [1], 4) = 0
[pid 23020] setsockopt(7, SOL_IPV6, IPV6_V6ONLY, [0], 4) = 0
[pid 23020] setsockopt(7, SOL_TCP, TCP_NODELAY, [1], 4) = 0
[pid 23020] bind(7, {sa_family=AF_INET6, sin6_port=htons(80), inet_pton(AF_INET6, "::", &sin6_addr), sin6_flowinfo=0, sin6_scope_id=0}, 28) = -1 EADDRINUSE (Address already in use)
[pid 23020] write(2, "(98)Address already in use: AH00"..., 82(98)Address already in use: AH00072: make_sock: could not bind to address [::]:80
) = 82

You'll notice bind is being called twice. The first time it works. The second time, it fails because the address is already in use—which it is, because it was just bound.

I have confirmed on my apache config (Apache 2.4 on Debian testing/unstable) that I can make this happen by having Listen 80 in the config twice. I suspect you've done the same, or something very similar.

2
  • Even without the strace the duple/multiple listen lines on same port has bitten me too.
    – Manwe
    Aug 8, 2013 at 10:35
  • This looks like IPv6 port 80 being bound twice.
    – Nils
    Aug 9, 2013 at 9:31
1

Looks like your problem might be related to attempting to bind IPV6 address instead of IPV4. Example Apache is trying to bind to ::1 and 127.0.0.1, since you don't have IPv6 configured - it attempts to bind do 127.0.0.1 twice. Solutions:

  • check if localhosts resolves to IPv4 IP (getent hosts localhost)

  • check /etc/hosts and remove any IPv6 adresses if you are not using IPv6 (especially localhost one)

If you are not able to update /etc/hosts - change httpd.conf or ports.conf to bind to IP, rather then name (Listen 127.0.0.1:80).

0

It looks from the error message that Apache is trying to bind using IPv6. Does your host have IPv6 enabled?

1
  • Welcome to Unix & Linux Stack Exchange! Please don't add comments as answers. Use actual comments when seeking clarification of any issues.
    – Braiam
    Aug 8, 2013 at 16:28

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .