Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

share|improve this question

migrated from stackoverflow.com May 1 '11 at 15:47

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

1  
i always refresh my memory on this topic from this article debuntu.org/2006/02/22/7-virtual-hosting-using-apache-2 –  igor milla Apr 30 '11 at 11:00
add comment

1 Answer 1

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

share|improve this answer
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
    
+1 Thanks. Let me try it... –  Awan Apr 30 '11 at 11:03
    
Its working...Thanks alot.. –  Awan Apr 30 '11 at 11:09
add comment

Your Answer

 
discard

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.