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

I keep getting this warning when I (re)start Apache.

* Restarting web server apache2 apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName

... waiting apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName [ OK ]

This is the content of my etc/hosts file:

#127.0.0.1  hpdtp-ubuntu910
#testproject.localhost  localhost.localdomain   localhost
#127.0.1.1  hpdtp-ubuntu910

127.0.0.1   localhost
127.0.0.1   testproject.localhost
127.0.1.1   hpdtp-ubuntu910



# The following lines are desirable for IPv6 capable hosts
::1     localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts

This is the content of my /etc/apache2/sites-enabled/000-default file:

<VirtualHost *:80>
  ServerName testproject.localhost
  DocumentRoot "/home/morpheous/work/websites/testproject/web"
  DirectoryIndex index.php
  <Directory "/home/morpheous/work/websites/testproject/web">
    AllowOverride All
    Allow from All
  </Directory>

  Alias /sf /lib/vendor/symfony/symfony-1.3.2/data/web/sf
  <Directory "/lib/vendor/symfony/symfony-1.3.2/data/web/sf">
    AllowOverride All
    Allow from All
  </Directory>
</VirtualHost>

When I go to http://testproject.localhost, I get a blank page.

Can anyone spot what I am doing wrong?


Solution 1:

By default Ubuntu doesn't specify a ServerName in the Apache configuration, because it doesn't know what the name of your server is. It tries a reverse lookup on your IP address, which returns nothing, so it just has to use the IP address as the ServerName.

To fix it, either add a ServerName directive outside of any virtual host - e.g. in /etc/apache2/httpd.conf, or set up a reverse DNS response for your primary IP address - in this case, 127.0.1.1

It's perfectly fine to ignore it also.

Solution 2:

Here's a quick fix:

echo ServerName $HOSTNAME > /etc/apache2/conf.d/fqdn

Solution 3:

Another way around that warning is to put a fully qualified domain name on the 127.0.1.1 line of /etc/hosts. It doesn't even have to be a fqdn that would actually resolve to anything on a dns server.

127.0.1.1  hpdtp-ubuntu910.lan  hpdtp-ubuntu910

would do the trick, while also preserving the behavior of any programs that aren't expecting the extra .lan. The order is important; names with more levels should be specified first, as in this example where the .lan address comes before the other address.