Apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1

I run the command on server:

apachectl configtest

I see the message

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
Syntax OK

So how can I get rid of it? How do I find and fix ServerName directive on a Debian Linux server?

  1. First, find your server’s IP address using the ip command or hostname command:
hostname -I
ip a s

Here is my IP (you might get public IPv4/IPv6, it all depends upon your server config and networking set up)

10.105.28.9
  1. Say your server name server1.cyberciti.biz, then update the /etc/hosts file as follows:
10.105.28.9 server1.cyberciti.biz
  1. Finally update Apache 2 config file /etc/apache2/apache2.conf (/etc/httpd/httpd.conf on RHEL/CentOS/Fedora) as follows to match your server’s IP address:
ServerName  10.105.28.9
  1. Test config:
sudo apache2ctl configtest
  1. Restart or reload httpd/apache2 web server
## Debian/Ubuntu Linux 
sudo systemctl restart apache2.service
## centos/rhel/fedora
sudo systemctl restart httpd.service

Linux sysadmin blog - Linux/Unix Howtos and Tutorials - Linux bash shell scripting wiki