Tuesday, November 6, 2012

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>  
 <VirtualHost *:80>  
   DocumentRoot "/var/www/mysite"  
   ServerName mysite.localhost  
 </VirtualHost>  

One also need to create the entry in "/etc/hosts" like this.

 127.0.0.1    localhost  
 127.0.0.1    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 stackoverflow.com.


2 comments:

  1. It is such an important topic and ignored by so many, even professionals. I thank you to help making people more aware of possible issues.
    Way2sms login

    ReplyDelete
  2. It is such an important topic and ignored by so many, even professionals. I thank you to help making people more aware of possible issues.
    Way2sms login

    ReplyDelete