apr_sockaddr_info_get() failed for server

About this error of Apache2:

apr_sockaddr_info_get() failed for server
Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName

Read the documentation about ServerName:

https://httpd.apache.org/docs/2.4/mod/core.html#servername

The ServerName directive may appear anywhere within the definition of a server. However, each appearance overrides the previous appearance (within that server).

If no ServerName is specified, the server attempts to deduce the client visible hostname by first asking the operating system for the system hostname, and if that fails, performing a reverse lookup on an IP address present on the system.

If you run the command hostname, you will possibly see the address Apache is using. If it’s a name that cannot be looked up (check with host your-hostname) this will likely be the reason Apache complains. If you do have a valid server name, one that can be looked up, use that. (Otherwise you should probably be using localhost.)

To change it without rebooting:

hostname new-valid-hostname

Change it permanently: edit /etc/hostname.


I wrote this as a reminder that if you can use a valid domain name, there is no need to edit /etc/hosts (something that is often suggested as a solution).