DevOpsil
Apache
85%
Needs Review

Fix Apache 'AH00558: Could not reliably determine server's FQDN'

Zara BlackwoodZara Blackwood3 min read

The Error

When starting or restarting Apache, you see this warning:

AH00558: apache2: Could not reliably determine the server's fully qualified domain name,
using 127.0.1.1. Set the 'ServerName' directive globally to suppress this message.

While Apache still starts, this warning can cause confusion and may lead to incorrect behavior in virtual host resolution and redirect generation.

Root Cause

Apache tries to determine its own hostname at startup by performing a reverse DNS lookup. When the system hostname does not resolve to a fully qualified domain name, or when /etc/hosts does not map the hostname to a proper FQDN, Apache cannot determine what name to use. It falls back to the IP address and logs the AH00558 warning.

This is common on:

  • Fresh server installs where the hostname is set to something like ubuntu or localhost
  • Cloud instances where the hostname is an internal identifier
  • Docker containers with minimal network configuration

Step-by-Step Fix

1. Check your current hostname

hostname
hostname -f

If hostname -f returns an error or a non-FQDN value (no dots), that confirms the issue.

2. Set the ServerName directive globally

Create or edit the global Apache configuration:

On Debian/Ubuntu:

echo "ServerName localhost" | sudo tee /etc/apache2/conf-available/servername.conf
sudo a2enconf servername
sudo systemctl reload apache2

On RHEL/CentOS/Rocky:

echo "ServerName localhost" | sudo tee -a /etc/httpd/conf/httpd.conf
sudo systemctl reload httpd

For production servers, use your actual domain instead of localhost:

ServerName www.example.com

3. Verify the fix

# Debian/Ubuntu
sudo apache2ctl configtest

# RHEL/CentOS
sudo httpd -t

You should see:

Syntax OK

The AH00558 warning should no longer appear.

Rather than just suppressing the warning, set a proper FQDN on the server:

# Set the hostname
sudo hostnamectl set-hostname web01.example.com

# Update /etc/hosts
sudo tee -a /etc/hosts <<EOF
127.0.1.1   web01.example.com web01
EOF

Verify:

hostname -f
# web01.example.com

5. Restart Apache cleanly

sudo systemctl restart apache2   # Debian/Ubuntu
sudo systemctl restart httpd      # RHEL/CentOS

Check the journal for any remaining warnings:

journalctl -u apache2 --no-pager -n 20

Prevention Tips

  • Set ServerName in your base configuration template. Whether you use Ansible, Puppet, or manual setup, always include a global ServerName directive.
  • Configure hostnames during provisioning. Use cloud-init or your IaC tool to set a proper FQDN before Apache is installed.
  • Use apache2ctl configtest in CI/CD. Before deploying Apache configuration changes, run a syntax check to catch missing directives early.
  • In Docker, set the hostname explicitly. Use --hostname in docker run or the hostname directive in Docker Compose to give the container a predictable FQDN.
Share:

Was this article helpful?

Zara Blackwood
Zara Blackwood

Platform Engineer

Terraform enthusiast, platform builder, DRY advocate. I believe infrastructure should be versioned, reviewed, and deployed like any other code. GitOps or bust.

Related Articles

ApacheQuick RefBeginnerNeeds Review

Fix Apache mod_rewrite Not Working

Diagnose and fix Apache mod_rewrite rules not being applied, covering module loading, AllowOverride settings, .htaccess issues, and rewrite logging.

Aareez Asif·
3 min read

More in Apache

View all →

Discussion