Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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?

share|improve this question
    
are you starting it as root? By default only root can open ports below 1024. –  onse Apr 2 '13 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. –  Gunner Barnes Apr 2 '13 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 –  hbdgaf Apr 2 '13 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 '13 at 19:57
1  
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. –  Gunner Barnes Apr 3 '13 at 14:28

6 Answers 6

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.

share|improve this answer

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.

share|improve this answer
up vote 0 down vote accepted

I've figured it out. 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.

share|improve this answer
    
I also had duplicate Listen 80 commands in both my httpd.conf and ports.conf –  Gunner Barnes Apr 4 '13 at 15:52

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.

share|improve this answer
    
netstat -antp | grep 80 outputs nothing as well. –  Gunner Barnes Apr 3 '13 at 18:39
    
can you copy and paste your output of netstat -antp | grep 80? –  Dylan Dodds Apr 3 '13 at 18:45
    
There is literally no output. –  Gunner Barnes Apr 3 '13 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 –  Dylan Dodds Apr 3 '13 at 18:53

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

share|improve this answer

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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