Creating virtual hosts in apache2

Recently I was trying to create a facebook app and thought of creating virtual hosts on my machine where I possibly could test it. Here is the steps I took to create two virtual hosts on my Linux Mint.First install LAMP stack if you don’t have it already

 sudo apt-get install lamp-server^ -y  

(Don’t forget the caret ‘^’)

Now define the following in “/etc/apache2/conf/extra/httpd-vhosts.conf” file

 NameVirtualHost *:80  
If the above mentioned file does not exist create it.
Also make sure that “/etc/apache2/httpd.conf” has this line
 Include conf/extra/httpd-vhosts.confconf  
NameVirtualHost needs to be all conf files only once so make sure that “/etc/apache2/ports.conf” has got it commented out.
 #NameVirtualHost *:80  
Now create the definition of virtual hosts like below.
 NameVirtualHost *:80  
 <VirtualHost *:80>  
    DocumentRoot "/var/www"  
    ServerName localhost  
 <VirtualHost *:80>  
   DocumentRoot "/var/www/mysite"  
   ServerName mysite.localhost  
One also need to create the entry in “/etc/hosts” like this.    localhost    mysite.localhost  
Now you should be able to test your sites.
Thanks for reading and much credit goes to guys on internet for helping out specially on

via Blogger


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s