Fix Apache 'AH00558: Could not reliably determine server's FQDN'
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
ubuntuorlocalhost - 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.
4. Fix the underlying hostname (recommended)
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
ServerNamein your base configuration template. Whether you use Ansible, Puppet, or manual setup, always include a globalServerNamedirective. - Configure hostnames during provisioning. Use cloud-init or your IaC tool to set a proper FQDN before Apache is installed.
- Use
apache2ctl configtestin CI/CD. Before deploying Apache configuration changes, run a syntax check to catch missing directives early. - In Docker, set the hostname explicitly. Use
--hostnameindocker runor thehostnamedirective in Docker Compose to give the container a predictable FQDN.
Was this article helpful?
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
Apache 301 Redirect Loop: Diagnosing And Fixing Infinite Redirect Chains In VirtualHost And .htaccess Configurations
Few things are more frustrating than deploying what you think is a clean redirect configuration, only to have your browser throw an `ERR_TOO_MANY_REDIRECTS...
Apache 413 Request Entity Too Large: Fixing File Upload Failures With LimitRequestBody And PHP Configuration
The 413 error means Apache is rejecting your upload before it even hits PHP. Here's exactly what to change and where. Two layers can block large uploads: 1...
Apache 500 Internal Server Error: Diagnosing .htaccess Syntax Failures And Module Conflicts Step By Step
If you've been running web infrastructure long enough, you know the 500 Internal Server Error is Apache's way of saying "something's broken, and I'm not go...
Apache 403 Forbidden Error After Directory Permissions Fix: Troubleshooting SELinux And File Contexts
You've just spent an hour wrestling with Apache file permissions, carefully setting ownership to `apache:apache` and permissions to `755` on your directori...
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.
Apache Mod_status Real-Time Server Monitoring With Grafana And Prometheus Integration
Monitoring Apache without proper observability tooling is like flying blind. You might catch a problem after your users start complaining, but by then, you...
More in Apache
View all →Apache Mod_security WAF Rules For OWASP Top 10 Protection
If you're running Apache in production without a Web Application Firewall, you're essentially leaving your front door unlocked. mod_security is the industr...
Apache Performance Tuning: MPM, KeepAlive, and Caching
Tune Apache performance by choosing the right MPM, configuring KeepAlive correctly, and enabling mod_cache for significant throughput gains.
Apache as a Reverse Proxy: mod_proxy Configuration Guide
Configure Apache as a reverse proxy using mod_proxy to route traffic to backend applications with load balancing and health checks.
Apache SSL/TLS Hardening: Get an A+ on SSL Labs
Harden Apache SSL/TLS configuration to achieve an A+ rating on Qualys SSL Labs with modern cipher suites and security headers.