Common causes
- No ServerName directive in the main config (apache2.conf or httpd.conf)
- The server's hostname has no matching entry in /etc/hosts
- A fresh Apache install where only virtual hosts define ServerName
- A container image where the hostname is a random ID
- The hostname is not a fully qualified domain name
How to fix it
- Set a global ServerName on Debian/Ubuntu. Create /etc/apache2/conf-available/servername.conf with the line ServerName localhost (or your real hostname). Enable it with sudo a2enconf servername.
- Set it on RHEL, CentOS or Alma. Open /etc/httpd/conf/httpd.conf, find the commented #ServerName www.example.com:80 line, and set ServerName localhost or your server's FQDN.
- Test and reload. Run sudo apachectl configtest. It should print Syntax OK without the AH00558 warning. Then run sudo systemctl reload apache2 (or httpd).
- Check the hostname mapping. Run hostname -f. If it fails, add a line such as 127.0.1.1 server1.example.com server1 to /etc/hosts.
- Look for the real error if Apache will not start. If Apache still fails, run sudo journalctl -u apache2 -n 50. Errors like port already in use or a syntax error are the actual problem.
Add a global ServerName on Debian/Ubuntu
echo 'ServerName localhost' | sudo tee /etc/apache2/conf-available/servername.conf
sudo a2enconf servername
sudo apachectl configtest
sudo systemctl reload apache2 How to stop it happening again
- Set a global ServerName in your provisioning script
- Give servers a proper FQDN hostname
- Keep ServerName set in every virtual host too
- Read the full configtest output, not just the first line