1

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

For example I have two files like this:

/var/www/project1/index.php
/var/www/project2/index.php

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

And

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?

Thanks

1

1 Answer 1

4

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
</VirtualHost>

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
127.0.0.1    project1.dev

Is that helpful or do you need some more info?

2
  • 2
    and don't forget to reload apache after sudo /etc/init.d/apache2 reload
    – igor milla
    Apr 30, 2011 at 10:58
  • Ah, good catch! Apr 30, 2011 at 11:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .