79

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?

6
  • are you starting it as root? By default only root can open ports below 1024.
    – onse
    Apr 2, 2013 at 15:02
  • Yes, I am. It was running at one point when I had just one virtual host configured, so I've since removed the other virtual host to try to remedy the issue, but no luck with that either. Apr 2, 2013 at 15:15
  • Does you host have something running on port 80 and you're in bridged mode for the guest? I don't know that it would do that, but it seems probable Apr 2, 2013 at 15:41
  • Have you tried the suggestions from Starting apache fails (could not bind to address 0.0.0.0:80)? And please also include the output of grep -ri listen /etc/apache and sudo netstat -ntlp | grep 80.
    – gertvdijk
    Apr 2, 2013 at 19:57
  • 2
    grep -ri listen /etc/apache2 outputs: etc/apache2/httpd.conf: Listen 80 /etc/apache2/httpd.conf: Listen 443 /etc/apache2/ports.conf: Listen 80 /etc/apache2/httpd.conf: Listen 443 /etc/apache2/httpd.conf: Listen 443 sudo netstat -ntlp | grep 80 outputs nothing at all. Apr 3, 2013 at 14:28

12 Answers 12

50

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/www.conf.

To find out, use: grep -ri listen /etc/apache2

Keep Listen 80 in just a single place.

0
41

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 1047

Where 1047 is the pid of the program running on port 80.You can replace the pid that you obtained from netstat

5
  • wow!... and here i am 48 hours after sending a ticket to inmotionhosting and waiting for a reply. thank you
    – Amjo
    May 24, 2018 at 8:54
  • 8
    What does this mean? I'm not getting a PID or name. tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN - Aug 29, 2018 at 19:21
  • @AaronFranke Can you please try running this command in Terminal after maximising the window? Aug 30, 2018 at 6:03
  • 7
    @AaronFranke run it with sudo. You might not have the permissions to view. Mar 2, 2019 at 16:37
  • Thank you! Years later, but your solution really saved me!
    – jimb
    May 19, 2021 at 13:41
21

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
3
  • Thanks a ton! After all tries this worked for me.
    – Vivek
    Feb 10, 2019 at 15:38
  • Had the same issue in a preconfigured LAMP on Digital Ocean
    – Rob
    Nov 30, 2019 at 17:02
  • i remember only install apache2, and skip this answer. then trying ohter answer, but none working. but when i try this answer. its working now. thankyou
    – Muklas
    Aug 7, 2023 at 23:01
15

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 443

That 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 apache2

Yes, 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 running

A 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/K09apache2

Reboot 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/apache2

Instead, start the apache2 like this:

sudo service apache2 start

And 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.

2
  • 1
    Enjoyed reading and using your tips! Thanks for writing 'the way you debugged it'!
    – RamValli
    Jul 22, 2016 at 7:15
  • great instruction, man! Helped a lot, especially that you really described your way of troubleshooting! May 7, 2020 at 14:57
13

When 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.

4

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.

1
  • 3
    I also had duplicate Listen 80 commands in both my httpd.conf and ports.conf Apr 4, 2013 at 15:52
3

Not just duplicate mentions of

Listen 80

but also mention of this in addition to Listen 80

Include ports.conf
1
  • 1
    Yep this was the problem for me.. Remember to check the sites-available/ files and ports.conf Nov 27, 2019 at 22:25
2

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.conf

Or close the application running on port 80:

netstat -antp | grep 80

To find what is running on port 80.

4
  • netstat -antp | grep 80 outputs nothing as well. Apr 3, 2013 at 18:39
  • can you copy and paste your output of netstat -antp | grep 80? Apr 3, 2013 at 18:45
  • There is literally no output. Apr 3, 2013 at 18:47
  • hmm that's odd, try changing the port to 81 if not it's not the port being blocked there's another error you can check apache2 errors in /var/log/apache2/error.log Apr 3, 2013 at 18:53
2

Just 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

2

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.

0

Try sudo service apache2 stop And Restart Apach again

0

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.log

But 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.

You must log in to answer this question.

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