Apache fails to start, Address already in use (but not really)
Matthew Harrington
I'm trying to set up a VM running Ubuntu 12.04. I have two virtual hosts configured using port 80, but Apache will not start.
I get this error:(98) Address already in use: make_sock: could not bind to address 0.0.0.0:80
The output of netstat -tulpn shows that nothing is using port 80. What could possibly be causing this?
12 Answers
Make sure you are not declaring Listen 80 twice in .conf files.
For example, you might have it both in ports.conf and inn sites-enabled/.
To find out, use: grep -ri listen /etc/apache2
Keep Listen 80 in just a single place.
Answering the way I solved out this issue. May be helpful to someone in future.
Try netstat -ltnp | grep :80
This would return something like
tcp6 0 0 :::80 :::* LISTEN 1047/apache2
Then run
sudo kill -9 1047Where 1047 is the pid of the program running on port 80.You can replace the pid that you obtained from netstat
I had a Nginx server listening on my AWS EC2 server, I think it got configured when I was building the EC2, hence was I getting Address already in use error. So I stopped the service and started the Apache2 service:
sudo service nginx stop
sudo service apache2 start 2 I got this error on a fresh install when starting apache2 Ubuntu 12.10.
It's a bug in the apache2. It gets hung in the background. Here is my walkthrough to where the bugs might be in the software.
Here's the error I got:
el@titan:~$ sudo service apache2 start * Starting web server apache2
(98)Address already in use: make_sock: could not bind to address 0.0.0.0:80
no listening sockets available, shutting down
Unable to open logs
Action 'start' failed.
The Apache error log may have more information. [fail]Address already in Use? What could be using it? Check it out:
el@titan:~$ grep -ri listen /etc/apache2
/etc/apache2/apache2.conf:# supposed to determine listening ports for incoming connections, and which
/etc/apache2/apache2.conf:# Include list of ports to listen on and which to use for name based vhosts
/etc/apache2/ports.conf:Listen 80
/etc/apache2/ports.conf: Listen 443
/etc/apache2/ports.conf: Listen 443That means apache2 is preventing apache2 from starting. Bizarre. This will confirm:
el@titan:~$ ps -ef | grep apache2
root 1146 954 0 15:51 ? 00:00:00 /bin/sh /etc/rc2.d/S91apache2 start
root 1172 1146 0 15:51 ? 00:00:00 /bin/sh /usr/sbin/apache2ctl start
root 1181 1172 0 15:51 ? 00:00:00 /usr/sbin/apache2 -k start
root 1193 1181 0 15:51 ? 00:00:00 /bin/bash /usr/share/apache2/ask-for-passphrase 127.0.1.1:443 RSA
el 5439 5326 0 16:23 pts/2 00:00:00 grep --color=auto apache2Yes, in this case apache2 is running, I was trying to start apache2 a second time on the same port.
What confuses me is that service reports that apache2 is NOT running:
el@titan:~$ sudo service apache2 status
Apache2 is NOT running.And when you query apache2ctl for its status, it hangs.
root@titan:~# /usr/sbin/apache2ctl status
**hangs until Ctrl-C is pressed.So Ubuntu seems to be having trouble managing apache2 on bootup. Time to stop apache2:
root@titan:~# /usr/sbin/apache2ctl stop
httpd (no pid file) not runningA big clue! You try to stop apache2 and it lost the process id! So Ubuntu can't stop apache2 because it doesn't know where it is!
You would think a reboot would fix it, but it doesn't because apache2 starts on boot and hangs. The normal boot process for apache2 is not working right.
So How to fix it?
I was able to fix this by analyzing the ps command output. Notice that the ps command tells us that that process was started by "/etc/rc2.d/S91apache2 start".
That is the offending program that needs a swift kick.
/etc/rc2.d/S91apache2 is the symbolic link used to start apache2 for you when the computer starts. For some reason it seems to be starting apache2 and then hangs. So we'll have to tell it to not do that.
So go take a look at that /etc/rc2.d/S91apache2.
el@titan:/etc/rc2.d$ ls -l
lrwxrwxrwx 1 root root 17 Nov 7 21:45 S91apache2 -> ../init.d/apache2*It's a symbolic link that we don't want it to be there. Do this to prevent apache2 from starting on boot:
root@titan:~# sudo update-rc.d -f apache2 remove Removing any system startup links for /etc/init.d/apache2 ... /etc/rc0.d/K09apache2 /etc/rc1.d/K09apache2 /etc/rc2.d/S91apache2 /etc/rc3.d/S91apache2 /etc/rc4.d/S91apache2 /etc/rc5.d/S91apache2 /etc/rc6.d/K09apache2Reboot the computer to make sure apache2 doesn't start and hang. Ok good. Now you COULD put apache2 back the way it was, but that would make it fail again.
root@titan:~$ sudo update-rc.d apache2 defaults //(don't do this) Adding system startup for /etc/init.d/apache2 ... /etc/rc0.d/K20apache2 -> ../init.d/apache2 /etc/rc1.d/K20apache2 -> ../init.d/apache2 /etc/rc6.d/K20apache2 -> ../init.d/apache2 /etc/rc2.d/S20apache2 -> ../init.d/apache2 /etc/rc3.d/S20apache2 -> ../init.d/apache2 /etc/rc4.d/S20apache2 -> ../init.d/apache2 /etc/rc5.d/S20apache2 -> ../init.d/apache2Instead, start the apache2 like this:
sudo service apache2 startAnd the apache2 is back up and serving pages again. There seems to be some serious bugs with apache2/Ubuntu 12.10 that causes apache2 to start and hang. This is a workaround, I suppose the fix is to get newer versions of apache2 and Ubuntu and hope for the best.
2When I had this problem, it turned out to be because my Apache couldn't start on boot because I had an SSL site that required a password to be entered for the certificate.
A good way to tell whether this is the case for you is to run a ps -ef | grep apache: if this returns processes that look like /bin/bash /usr/share/apache2/ask-for-passphrase mysite.com:443 RSA then it's waiting for a password to be entered in a terminal that you will never see.
First, I killed the hung process (sending a kill -HUP to the process ID for /usr/sbin/apache2 process should be enough to kill the other ones too, but do another ps -ef | grep apache to be sure).
Then I followed the instructions in this post to create an SSL password file that didn't require a password to be entered. Then a service apache2 start worked fine, and Apache started properly after a reboot.
I've figured it out. I had duplicate Listen 80 commands in both my httpd.conf and ports.conf
Also, in copying the config file over for that server that's being virtualized, I neglected to notice that the error log directory had been changed. Looking into that error log, I noticed that the directory for the mime.types config file was incorrect in my httpd.conf file. I updated that parameter, and the server started up fine.
Not just duplicate mentions of
Listen 80but also mention of this in addition to Listen 80
Include ports.conf 1 This means you're port 80 is already being used, either change the port for apache2 (which I don't recommend) by editing:
/etc/apache2/ports.confOr close the application running on port 80:
netstat -antp | grep 80To find what is running on port 80.
4Just a hint for anyone, who perhaps is running VirtualBox with NAT networks. I found, having a NAT rule between my guest and host had set itself up, binding the port
I couldn't determine what my problem was.
There were no duplicates for listening on port 80 with grep -ri listen /etc/apache2 and I could see no other application using port 80 with netstat.
I'm running a website with a certificate installed and so eventually I figured I don't necessarily need to listen on port 80, so I just deleted Listen 80 line in /etc/apache2/ports.conf and now it works.
Try sudo service apache2 stopAnd Restart Apach again
I had same problem exactly after a reboot and spending hours to debug none of above answers could solve my apaches startup error.. There was no error description in logs.. Port 80 and 443 was not in use.. No duplicate Listen directives.. and totally not any clues to show me why apache is not working as expected after reboot!
I even tried running apaches startup debugger:
# For My CentOS 7:
httpd -e warn -E /var/log/my-custom-apache-debugging.log
# For Ubunto as asked in question:
apache -e debug -E /var/log/my-custom-apache-debugging.logBut No chance!..
Finally I remembered that I enabled selinux on my last modifications some weeks ago and never reboot after that change.Disabling Selinux again and a final reboot solved this on my case.