Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Servers, nginx and Docker

Job for apache2.service failed: find the real reason in two commands

ErrorAddress already in use: make_sock: could not bind to address [::]:80

Short answer

The systemd message only says Apache did not start. The reason is in the Apache error log or in apache2ctl configtest. Two causes cover most cases: a syntax error in a config file, or another program already holding the port that Listen asks for. Test the config first, then check who owns the port.

  • Applies to Apache 2.4, Ubuntu 24.04
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Run the config syntax test. It names the file and line of a syntax error.

    sudo apache2ctl configtest
  2. 2Match what you see, then jump to its fix

    1. 1configtest prints a file name and line number instead of Syntax OKA configuration file has a syntax errorFix
    2. 2Address already in use: make_sock: could not bind to addressAnother process already listens on the portFix
    3. 3Apache fails right after you added a Listen directive, for example Listen 80 plus Listen 127.0.0.1:80Two Listen lines overlapFix

What does the error look like?

  • Address already in use: make_sock: could not bind to address [::]:80
  • apache2.service failed (systemctl status shows the unit as failed)

Cause 1 of 3

A configuration file has a syntax error

1Check

configtest parses the config files and reports either success or the particular syntax error. It is the same as apachectl -t.

sudo apache2ctl -t

2Fix

Open the file and line it names, correct the directive, then run the test again until it passes.

sudo apache2ctl configtest

3Verify

Start the service once the test passes.

sudo systemctl start apache2 && systemctl is-active apache2

Confirmed by httpd.apache.org

Did this fix it?

Cause 2 of 3

Another process already listens on the port

1Check

Listen decides which ports Apache binds. If another program owns the port, Apache cannot bind and exits. List the listeners on 80 and 443.

sudo ss -ltnp | grep -E ':(80|443) '

2Fix

Stop the other program, or change the Listen line in /etc/apache2/ports.conf to a free port.

# /etc/apache2/ports.conf
Listen 8080

3Verify

Run the test and start the service.

sudo apache2ctl configtest
sudo systemctl restart apache2

Confirmed by httpd.apache.org

Did this fix it?

Cause 3 of 3

Two Listen lines overlap

1Check

Overlapping Listen directives are a fatal error that stops the server from starting. Look at every Listen in the config tree.

grep -rn "^\s*Listen" /etc/apache2/

2Fix

Keep one Listen per address and port combination, and remove the overlapping line.

# keep only one of these
Listen 80

3Verify

Test and restart.

sudo apache2ctl configtest
sudo systemctl restart apache2

Confirmed by httpd.apache.org

Did this fix it?

How do I stop it coming back?

  • Run apache2ctl configtest before every restart or reload; apache2ctl restart does it for you.
  • Keep Listen lines only in ports.conf.
  • Check ss -ltnp before moving another service onto port 80 or 443.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Related fixes

Servers

dnf cannot install MySQL on Amazon Linux 2023

dnf cannot find a mysql-server package on Amazon Linux 2023

Amazon Linux 2023 documents MariaDB, not MySQL, as its database server, with packages named mariadb105 and mariadb105-server.

3 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.