How To Fix Apache Configuration Error AH00558: Could not reliably determine the server's fully qualified domain name.

This is the seventeenth in a series of posts, featuring Protips, tips, tricks, hacks, and secrets provided by Our Team 🙊 — We want to share our top tips for the growing and thriving Linux community out there. Because sometimes you need a little help...

How To Fix Apache Configuration Error AH00558: Could not reliably determine the server's fully qualified domain name.

An Apache AH00558: Could not reliably determine the server's fully qualified domain name message occurs when Apache is not configured with a global ServerName directive. The warning is only informative yet annoying, and will in any case prevent Apache from operating normally.


Troubleshooting using systemctl


The first step in dealing with the AH00558 problem is to use systemctl to verify Apache's status. The output contains all of the information required to help us resolve the issue.

Let's run the following to check Apache’s status:

$ sudo systemctl status apache2.service -l --no-pager

The -l option tells systemctl to output the complete line, rather than using ellipses (…) for long lines.

The --no-pager flag will output the complete log to your screen without using a program like less, which only exposes one screen of material at a time.

The output should be similar to the following:

Output

● apache2.service - The Apache HTTP Server
   Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
  Drop-In: /lib/systemd/system/apache2.service.d
           └─apache2-systemd.conf
   Active: active (running) since Mon 2024-01-22 14:54:23 UTC; 7h ago
  Process: 1814 ExecStart=/usr/sbin/apachectl start (code=exited, status=0/SUCCESS)
 Main PID: 46 (apache2)
    Tasks: 55 (limit: 2750)
   CGroup: /system.slice/apache2.service
           ├─46 /usr/sbin/apache2 -k start
           ├─47 /usr/sbin/apache2 -k start
           └─48 /usr/sbin/apache2 -k start

Jan 22 14:54:23 43d2cd344s1 systemd[1]: Starting The Apache HTTP Server...
Jan 22 14:54:23 43d2cd344s1 apachectl[35]: AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1. Set the 'ServerName' directive globally to suppress this message
Jan 22 14:54:23 43d2cd344s1 systemd[1]: Started The Apache HTTP Server.



Troubleshooting using apachectl


The apachectl configtest command inspects the syntax of Apache configuration files. It also checks the files that it recursively points to.

Let's run the following command:

$ sudo apachectl configtest

The output should be similar to the following:

Output

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

Syntax OK


Generally speaking, it alerts you that Apache could not identify a valid ServerName directive in its configuration file; nothing more, nothing less.



Setting a Global ServerName Directive


To overcome this issue, we need to add a ServerName directive to our Apache configuration. To manage requests for numerous sites on a single server, Apache employs the ServerName directive to translate incoming HTTP requests to an IP address or DNS hostname, which is then handled by VirtualHost directives.

Let's open the /etc/apache2/apache2.conf file with root privileges with our preferred text editor here; nano.

$ sudo nano /etc/apache2/apache2.conf


Add a line containing ServerName 127.0.0.1 to the end of the file:

. . .
. .
.
 
# Include the virtual host configurations:
IncludeOptional sites-enabled/*.conf

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

ServerName 127.0.0.1


Run apachectl to test that the configuration is valid.

$ sudo apachectl configtest

Output
Syntax OK


Now, let's reload Apache’s configuration and check its status using systemctl reload along with systemctl status command:

$ sudo systemctl reload apache2 && sudo systemctl status apache2

Output

● apache2.service - The Apache HTTP Server
     Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
     Active: active (running) since Mon 2024-01-22 14:54:23 UTC; 7h ago
       Docs: https://httpd.apache.org/docs/2.4/
    Process: 9025 ExecReload=/usr/sbin/apachectl graceful (code=exited, status=0/SUCCESS)
   Main PID: 1814 (apache2)
      Tasks: 56 (limit: 2750)
     Memory: 6.4M
        CPU: 2.574s
     CGroup: /system.slice/apache2.service
             ├─1814 /usr/sbin/apache2 -k start
             ├─9030 /usr/sbin/apache2 -k start
             └─9031 /usr/sbin/apache2 -k start

Jan 22 14:54:23 virtuallinux systemd[1]: Starting The Apache HTTP Server...
Jan 22 14:54:23 virtuallinux systemd[1]: Started The Apache HTTP Server.
Jan 22 14:54:25 virtuallinux systemd[1]: Reloading The Apache HTTP Server...
Jan 22 14:54:25 virtuallinux systemd[1]: Reloaded The Apache HTTP Server.
Jan 22 22:53:45 virtuallinux systemd[1]: Reloading The Apache HTTP Server...
Jan 22 22:53:45 virtuallinux systemd[1]: Reloaded The Apache HTTP Server.

Again, while this annoying message does not prevent Apache from running, it can be resolved by setting a global ServerName directive.

We hope this was of great use!