Linux  ·  high  ·  Web, PHP & databases

Apache will not start — port in use, ServerName, or a bad module

Apache is explicit about why it stopped. The startup output and the error log name the file and line.

What you see

systemctl start apache2 fails, or reports success while nothing is listening. AH00558 is a warning that is frequently mistaken for the cause.

What is actually wrong

Another process on port 80 or 443, a syntax error in a site file, a module enabled without its dependency, or a certificate path that does not exist.

Codes and articles

AH00558AH00072Address already in useCould not reliably determine the server's fully qualified domain nameAH01630

Fixes (2)

Find what already holds the port
Root shell15 minutesmedium riskreversible

Address already in use.

  1. Find the process.

    Shell
    sudo ss -tlnp | grep -E ':80 |:443 'sudo fuser -v 80/tcp 443/tcp
  2. It is usually nginx installed alongside Apache, or an old Apache process that did not exit.

    Shell
    systemctl is-active nginx apache2 httpd 2>/dev/nullps aux | grep -E 'apache|httpd|nginx' | grep -v grep

    Both web servers installed and both enabled is extremely common after following two different guides. Whichever starts first wins the port and the other fails at every boot.

  3. Decide which one should own the port and disable the other.

    Shell
    sudo systemctl disable --now nginxsudo systemctl enable --now apache2
  4. If both are wanted, put one behind the other on a different port rather than fighting over 80.

    Shell
    sudo sed -i 's/^Listen 80$/Listen 8080/' /etc/apache2/ports.confsudo systemctl restart apache2
Confirm it workedThe intended server is listening and answering.
Shell
sudo ss -tlnp | grep -E ':80 |:8080 'curl -sI http://localhost/ | head -3
If you need to undo itRe-enable whichever service was disabled.
Read the configuration test output
Root shell20 minuteslow riskreversible

A syntax error, a module problem, or the ServerName warning.

  1. Test the configuration. It names the file and the line.

    Shell
    sudo apachectl configtestsudo apache2ctl -S
  2. AH00558 about the fully qualified domain name is only a warning and never prevents startup. Silence it by setting ServerName, but do not spend time on it if the server is failing for another reason.

    Shell
    echo 'ServerName localhost' | sudo tee /etc/apache2/conf-available/servername.confsudo a2enconf servernamesudo systemctl reload apache2

    This warning appears at every start on a default install and is the thing most people latch on to. It is noise; the real error is elsewhere in the output.

  3. For a module error, enable the dependency as well as the module.

    Shell
    sudo a2enmod ssl headers rewrite proxy proxy_httpsudo systemctl restart apache2
  4. Check certificate paths actually exist if SSL is involved.

    Shell
    sudo apache2ctl -S 2>&1 | grep -i sslsudo grep -rn 'SSLCertificate' /etc/apache2/sites-enabled/ | while read -r l; do echo "$l"; done
  5. Read the error log for anything the test does not catch.

    Shell
    sudo journalctl -u apache2 -n 40 --no-pagersudo tail -40 /var/log/apache2/error.log
Confirm it workedconfigtest returns Syntax OK and the service starts and serves.
Shell
sudo apachectl configtest && systemctl is-active apache2
If you need to undo ita2dismod and a2disconf reverse the enables; restore edited files from backups.

Where this stops. This write-up was written and checked by hand. It says what each step changes, how to confirm it worked and how to reverse it, and anything destructive is flagged before you reach it. If it does not match what your machine is doing, search the Support Centre for the exact code or message — and when something needs a person, get in touch.