Take the 2-minute tour ×

I recently reinstalled ubuntu on my system and I cannot get virtual hosts to work properly.

What I'm trying to accomplish is typing 'test' on my browser and pointing to my local machine on the location /var/www/test

I have followed several tutorials on the subject, and after every one of them, w3m test outputs the contents of the index.html on the test directory as expected, but when I go to firefox/chrome and type 'test' in the address bar, the browser googles it and shows me results.

So I'm wondering if there is something wrong with my process.

What I've been doing so far is:

  1. sudo apt-get install lamp-server^
  2. sudo gedit /etc/hosts
  3. append ' test' to hosts file
  4. save and exit
  5. sudo gedit /etc/apache2/sites-available/test
  6. add the following lines to test:

    <VirtualHost *:80>
    ServerName test
    DocumentRoot /var/www/test
  7. save and exit
  8. sudo a2ensite test
  9. restart apache (tried sudo service apache2 restart, reload, and also rebooted the whole system)

Any clues as to why w3m shows me the correct file and browsers refuse to do so?

Please note that I have cleared Firefox and Chrome caches several times.


It looks like I had misconfigured my lamp server in the first place.

The above process worked just fine when I reinstalled lamp (sadly I had to reinstall OS too), with one slight modification.

In step 3, you do not have to append the name of the vhost to the hosts file, you have to append it to the line that starts with localhost (usually the first line)

I cannot accept any of the answers, since if someone faces the same difficulty in the future, none of the answers will give the solution.

I will have to search the configuration files to see exactly what was wrong, and the. I will post it.

share|improve this question

2 Answers 2

You might have a minor problem with your DNS resolution via /etc/hosts.

Since you appended test to /etc/hosts, the DNS resolver has two entries which refer to the same DNS name, test and localhost. Fixing this could go two directions.

  1. If you want an alias, add test to the original localhost line, rather than adding a new line. The result would be: localhost localhost.localdomain test
  2. If you want to have a dedicated IP address, use an alternate IP address on a new line. Fortunately, all of is loopback, so you can use any IP address in that range to create a secondary IP address for services: test test.localdomain
share|improve this answer
Yes, I already pointed it out to OP via chat on AU, but it appears he had done this correct and just doesn't bother updating the Q here. +1 for very clear explanation for what I was trying to tell him. –  gertvdijk Jan 6 '13 at 11:29
@AnPel It's not about accepting answers and there is something relevant. You can't expect other people to work on your questions this way. If you don't fix mistakes in the question you know of (not the same as mistakes in the steps), this will result in answers you are not helped with. This answer is one of them and wouldn't have to be there if you would have updated your question with the exact line in the file. This discourages people like RobGibson, probably. Your Q is fine besides that, though. –  gertvdijk Jan 7 '13 at 8:33
@AnPel I agree on your last comment. But again: Copy/pasting/linking the whole /etc/hosts is reliable and relevant. –  gertvdijk Jan 7 '13 at 10:36

Your browser is too smart, and thinks that if you enter a single word into the address bar, that you meant to search, rather than browse to a site. Enter in a complete URL instead, for instance:



share|improve this answer
Sadly, this is not the case. 'test' googles for test, and test takes me to test.com –  AnPel Jan 5 '13 at 16:58
You need to fix your browser, then. –  Michael Hampton Jan 5 '13 at 17:01
both chrome and firefox? I hope you are right since I've been breaking my head 2 days now but it feels like it's not a coincidence. Except each browser's preferences, where else should I start looking? –  AnPel Jan 5 '13 at 17:05
Browsers nowadays assume that anything you enter with an extension is meant as a search. You might also try test.localdomain, assuming localdomain is your local intranet domain name (default on most Linux distributions). –  Oldskool Jan 5 '13 at 17:19
@Oldskool localhost.localdomain takes me to the localhost. test.localdomain does not work. –  AnPel Jan 5 '13 at 17:26

Your Answer


