Apache 2 could not bind, address already in use

I installed Apache 2 on Ubuntu 12.10. When I try to start the service using sudo /etc/init.d/apache2 start, I get the following message.

*Starting web server apache2
(98)Address already in use: make_sock: could not bind to address 127.0.0.1:80
no listening sockets available, shutting down
Unable to open logs
Action 'start' failed.
The Apache error log may have more information.                                 [fail]

Solution 1:

It's well possible that you have something already running at (or "bound to") that port. Try this command to see processes in question:

sudo lsof -i :80

This lists processes listening on port 80. Once you found the culprit you know which process to kill or kill -9 (also as superuser).

Keep in mind that the Apache instance, assuming you had started that earlier, might have gone "stale" or become a zombie. In the latter case even a reboot may be necessary in some cases.

Otherwise go with the answer from dedunumax.

Solution 2:

Try sudo service apache2 start

then type

sudo service apache2 status

second command will display whether it is running or not.

Solution 3:

I got this error message with the following configuration:

# cat /etc/hosts
127.0.0.1   localhost
127.0.0.1   foo
...

# cat /etc/apache2/sites-enabled/foo
<VirtualHost foo:80>
...

# cat /etc/apache2/ports.conf 
...
NameVirtualHost *:80
Listen localhost:80
...

Changing ports.conf to the following solved the problem:

NameVirtualHost *:80
Listen 127.0.0.1:80