72

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?

migrated from superuser.com Jan 16 '10 at 20:55

This question came from our site for computer enthusiasts and power users.

11 Answers 11

52

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.

  • 3
    This is counter-intuitive. If I add the ServerName outside of any virtual hosts - how can I serve multiple virtual hosts from the same Apache server? (this afterall, is the point of named virtual servers) - UNLESS, you are saying that I can have more than 1 ServerName entry in (say) /etc/apache2/httpd.conf – user35402 Jul 17 '10 at 16:52
  • 7
    You can then add ServerName/ServerAlias inside VirtualHost blocks to make that VirtualHost only match the host names you want. Read httpd.apache.org/docs/2.2/mod/core.html#servername for the low-down. – crb Jul 17 '10 at 22:37
  • I've been searching for this answer for over an hour. So much crap on the internet concerning this, but this fixed my problem. Thx – Mike Mar 22 '13 at 5:32
  • @Mike you and others are genius! I've searching for this answer for four days. (Ok, not fully working days.). +1 because this is the first answer that explains that I can add a ServerName directive outside virtual hosts without affecting them. With that in mind, ReinoutS' solution worked for me (+1 to him, too). – Sony Santos Aug 8 '13 at 3:46
27

Here's a quick fix:

echo ServerName $HOSTNAME > /etc/apache2/conf.d/fqdn
  • Thanks. None of the fixes using /etc/hosts nor httpd.conf worked for me, but this did. – Ryan Jan 21 '13 at 18:53
  • 1
    Fixed it on Ubuntu 13.04 running apache2, thank you! – dmanexe May 16 '13 at 2:12
  • Worked fine on current Debian Wheezy :) thanks – DominikAngerer Apr 4 '15 at 14:51
16

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.

7

This solution works for my development needs:

Background:

Debian Linux Sid:
VirtualHost Development: I have 10 server names (10 virtualhost entries inside sites-available)

I assigned each one a unique localhost IP address inside /etc/hosts:

127.0.0.1   joe   localhost.localdomain   localhost
127.0.1.1   joe
127.0.1.2   joomla
127.0.1.3   schmoo
127.0.1.4   forrest
127.0.1.5   store
127.0.1.6   publisher
127.0.1.7   studios
127.0.1.8   drupal
127.0.1.9   graphics
127.0.1.10  wordpress
...

The following lines are desirable for IPv6 capable hosts

::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts

If you're going to add another virtualhost (I have quite a few for development) add an entry to another localhost IP address, and enable the site before restarting Apache 2.2:

127.0.0.11 *newhost*

For every entry you want to enable as a VirtualHost file:

/etc/apache2/sites-available/

joe joomla schoo forrest store publisher studios drupal graphics wordpress

All virtualhosts are enabled/disabled via a2ensite/a2dissite hostname

To suppress the error

Restarting web server: apache2apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName ... waiting apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName''

edit httpd.conf in /etc/apache2/httpd.conf [empty file in Debian]:

ServerName 127.0.1.1

Look up is then resolved for all names you add, comment out or disable down the line.

In case you forget: The sole VirtualHost *:80 entry only needs to be within the ports.conf file,

/etc/apache2/ports.conf

**NameVirtualHost *:80**
Listen 80

<IfModule mod_ssl.c>
   # If you add NameVirtualHost *:443 here, you will also have to change
   # the VirtualHost statement in /etc/apache2/sites-available/default-ssl
   # to <VirtualHost *:443>
   # Server Name Indication for SSL named virtual hosts is currently not
   # supported by MSIE on Windows XP.
   Listen 443
</IfModule>

<IfModule mod_gnutls.c>
   Listen 443
</IfModule>

Within your VirtualHost entry leave out VirtualHost *:80

Example: virtualhost joe

<VirtualHost *:80>
    **ServerAlias joe**
    **...**
</VirtualHost>
6

Setting ServerName in httpd.conf did not work for me. I fixed it by setting ServerName 127.0.0.1 in /etc/apache2/conf.d/name.

I'm running Ubuntu 12.10 Alpha3 and have ServerName defined in both spots.

Source: http://linuxconfig.net/manual-howto/error-solution-could-not-reliably-determine-the-servers-fully-qualified-domain-name.html

  • Cool, this worked for me also, had the same issue. – Priyank Bolia Sep 13 '12 at 13:51
5

You're missing a server configuration-level ServerName entry. You need to have a ServerName entry outside of any host, for Apache to use as its default.

Putting a ServerName entry inside a VirtualHost will not fix the problem. See ServerName Directive.

3

To fix it, we need to edit the /etc/apache2/httpd.conf or /etc/apache2.conf and add the following line:

ServerName nameofserver
  • 1
    You're right! But this answer duplicates the content of crb's answer without providing any new information or insight. I'd consider deleting it or adding more detail that is different from other people's answers. – Royce Williams Jan 8 '12 at 16:13
1

I believe you need to add ServerName for the default virtual host. Since it's not there, it is taking the default IP address. And it's a kind of warning. Your web server will still be functional I guess.

  • I dont understand your comment. I already have ServerName in my file: <VirtualHost 127.0.0.1:8080> ServerName mysite.localhost Could you please clarify you comment? – morpheous Jan 16 '10 at 20:41
  • 1
    For the -default- virtualhost, not just a specific virtualhost. – Kzqai May 11 '11 at 18:20
0
  1. you have to add ServerName in your httpd.conf file using following steps

    sudo gedit /etc/apache2/httpd.conf
    

    By default httpd.conf file will be blank. Now, simply add the following line to the file.

    ServerName localhost
    

    Save the file and exit from gedit. Finally restart the server.

    sudo /etc/init.d/apache2 restart
    

2) Add Include httpd.conf at the end of apache2.conf

-1

If an httpd.conf file doesn't already exist in your etc/apache2 directory after install, then the main apache configuration file, apache2.conf, will not have a reference to it so adding anything to a created httpd.conf will not do anything. You can simply add the line "ServerName hostname" to the apache2.conf file instead.

-1

Is /etc/hosts still have these entries. (I skipped some answers above)

127.0.0.1 localhost 127.0.0.1 testproject.localhost

Both IP address 127.0.0.1 is same here.

Give different IP address to testproject.localhost from loopback ip subnet.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.