Apache error "Could not reliably determine the server's fully qualified domain name"
6# 13.04 and older
This is just a friendly warning and not really a problem (as in that something does not work).
If you go to:
/etc/apache2/apache2.conf
and insert:
ServerName localhost
and then restart apache by typing into the terminal:
sudo systemctl reload apache2
the notice will disappear.
If you have a name inside /etc/hostname
you can also use that name instead of localhost
.
And it uses 127.0.1.1
if it is inside your /etc/hosts
:
127.0.0.1 localhost
127.0.1.1 myhostname
Preferred method
Troubleshooting Apache
If you get this error:
apache2: Could not determine the server's fully qualified domain name,
using 127.0.0.1 for ServerName
then use a text editor such as "sudo nano" at the command line or "gksudo gedit" on the desktop to create a new file,
sudo nano /etc/apache2/conf.d/fqdn
or
gksu "gedit /etc/apache2/conf.d/fqdn"
then add
ServerName localhost
to the file and save. This can all be done in a single command with the following:
echo "ServerName localhost" | sudo tee /etc/apache2/conf.d/fqdn
But on Ubuntu 14.04:
echo "ServerName localhost" | sudo tee /etc/apache2/conf-available/fqdn.conf
sudo a2enconf fqdn
Don't forget the ".conf" (without will not work).
13.10 or newer
As of Apache 2.4 - which is available by default as of 13.10 - you cannot use the method about adding a config file in the conf.d
directory.
Apache no longer uses the conf.d
directory. All the configuration files are stored inside /etc/apache2/conf-available
directory and all the configuration files should now have a .conf
extension.
In order to solve this message in Apache 2.4, we have to create a configuration file inside the conf-available directory. For example servername.conf
.
sudo vi /etc/apache2/conf-available/servername.conf
And inside this we just need to add one line
ServerName localhost
You can combine the previous two commands in one with:
echo "ServerName localhost" | sudo tee /etc/apache2/conf-available/servername.conf
If you want to use a domain name or any other name depending on the requirement its fine, just replace localhost
with whatever you need. Next you have to enable this configuration. For this, you need to run the following command:
sudo a2enconf servername
a2enconf
is a command to enable a configuration file in Apaches 2.4. Also note that servername
on the above command is from the name of the configuration file servername.conf
. If your configuration file was ngenericserver.conf
then you would have to write sudo a2enconf ngenericserver
.
After this reload the server and the above message will no longer bug you.
sudo service apache2 reload
or
sudo apache2ctl graceful
Now after this you will see that the message will not be shown again and the problem will be fixed.
Apache2 can also get the FQDN from a properly configured system hostname rather than hardcoded into the apache config file. Hardcoding it will also cause confusion if the hostname changes. You actually don't need any ServerName
directives in httpd.conf
or any apache config files.
Put the following in /etc/hosts
:
# IPv4 and IPv6 localhost aliases
127.0.0.1 hostname.domainname.com hostname localhost
::1 hostname.domainname.com hostname localhost
where hostname.domainname.com
is the FQDN of your machine.
Along with a properly configured hostname in /etc/hostname/
or with hostnamectl
, this will also help other services on your machine run properly (i.e. the login prompt, showing This is hostname.domainname.com
instead of This is hostname.unknown_domain
.)