I am trying to set-up some virtual hosts on a fresh install of Ubuntu 12.04 and not getting expected results. I am using this tutorial which I have used before without fail.

The challenge seems to come with restarting apache.

$> sudo service apache2 restart 
  * 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

If I go through all of the steps, the alias I am trying to establish renders the root of localhost in my browser not the path set in sites available file.

Attempting to troubleshoot this, I removed the site with a2dissite and removed the site in /etc/hosts. Restarting apache as above, I receive the same error result. So it would appear something is not working properly in the first place, never mind attempting to add more hosts.

/etc/hosts content without additional hosts, rendering error messages found above:

127.0.0.1   localhost
127.0.1.1   daniel-dell-ubuntu

# 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

Excerpt for the sites-available directory for lh-test_site

    DocumentRoot /var/www/test_site
    <Directory />
        Options FollowSymLinks
        AllowOverride None
    </Directory>
    <Directory /var/www/test_site/ >
        Options Indexes FollowSymLinks MultiViews
        AllowOverride None
        Order allow,deny
        allow from all
    </Directory>

Dani AI

Generated

Quick practical notes that fill the gaps in the thread: the two symptoms you saw — Apache warning about the "fully qualified domain name" and the virtual host serving the global localhost site instead of your test site — usually come from one of three causes: the virtual host file is not defined as a name‑based vhost, the requested hostname doesn't match any vhost ServerName/ServerAlias, or the default site is still first in the enabled list and therefore captures requests. was right to suggest adding a ServerName in the vhost and putting a matching hosts entry; that fixes the name matching. ’s /etc/hosts line using 127.0.1.1 for the machine hostname is normal on Ubuntu and is separate from the loopback entry you need for a test name.

Quick checklist to resolve and diagnose:

  • Make sure your site config is wrapped in a name-based vhost (VirtualHost for *:80) and has a ServerName (plus ServerAlias if you need extra names).
  • On Apache 2.2 (Ubuntu 12.04) confirm NameVirtualHost *:80 is present in ports.conf; on newer Apache versions that directive is ignored.
  • Add a hosts entry that maps the ServerName to the loopback you intend to use, then enable the site and reload Apache.
  • Disable the default site if it’s still enabled so it won’t shadow your vhost.

Useful commands to inspect what Apache actually sees:

sudo apache2ctl -S
sudo apache2ctl -t
tail -n 80 /var/log/apache2/error.log

You can also simulate requests with a custom Host header to force name lookup, for example with curl.

If you only want to silence the FQDN warning, set a global ServerName in Apache’s main config (for example to localhost) or add a tiny conf in conf-available and enable it. Finally, check file permissions on your DocumentRoot and remember that the first enabled vhost becomes the default when no name matches — that’s why older installs sometimes “worked” without an explicit ServerName.

Recommended Answers

All 2 Replies

You have to add the ServerName directive into the lh-test_site file:

ServerName testsite
DocumentRoot /var/www/test_site
<Directory />
    Options FollowSymLinks
    AllowOverride None
</Directory>
<Directory /var/www/test_site/>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride None
    Order allow,deny
    allow from all
</Directory>

then inside /etc/hosts add:

127.0.0.1 testsite

and run a2ensite as before, it should work.

Thanks for the input. Your advice helped and pointed out a flaw in the how-to I used to set-up all of the server aliases on my previous install of Ubuntu. Not one of those had a ServerName directive and they worked.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.