Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to create virtual hosts on ubuntu. I am using ubuntu and apache server.

For example I have two files like this:


I want that when I use in browser then it should point /var/www/project1/index.php


If I use in browser then it should point /var/www/project2/index.php

I have tried some articles but there are lot of information and I am unable to run it. I am new to ubuntu, Can someone tell me exact points and commands?


share|improve this question

migrated from May 1 '11 at 15:47

This question came from our site for professional and enthusiast programmers.

i always refresh my memory on this topic from this article – igor milla Apr 30 '11 at 11:00
up vote 4 down vote accepted

You define your virtual hosts by creating files in /etc/apache2/sites-available. For example:

# /etc/apache2/sites-available/
<VirtualHost *:80>
        DocumentRoot /var/www/

You can then enable them by running sudo a2ensite virtualhostname. For example, a2ensite Then reload apache by running with sudo service apache2 reload.

You will also need to add an entry to /etc/hosts so that you can access them using fake domain names in your browser. For example:

# /etc/hosts

Is that helpful or do you need some more info?

share|improve this answer
and don't forget to reload apache after sudo /etc/init.d/apache2 reload – igor milla Apr 30 '11 at 10:58
Ah, good catch! – stickmangumby Apr 30 '11 at 11:03
+1 Thanks. Let me try it... – Awan Apr 30 '11 at 11:03
Its working...Thanks alot.. – Awan Apr 30 '11 at 11:09

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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