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 project1.dev in browser then it should point /var/www/project1/index.php


If I use project2.dev 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?



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

# /etc/apache2/sites-available/project1.dev
<VirtualHost *:80>
        ServerName project1.dev
        ServerAlias www.project1.dev
        DocumentRoot /var/www/project1.dev/public_html

You can then enable them by running sudo a2ensite virtualhostname. For example, a2ensite project1.dev. 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    project1.dev

Is that helpful or do you need some more info?

  • 2
    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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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