How to create virtual website

I’m using Ubuntu 12.04.03 32bit

It’s possible to do virtual websites so domains are seen in locally. Here is tutorial how to do that.

First you need to install Apache. Here is tutorial how you do that: How to install LAMP

Find out your ip address and add it to your hosts file

$ ifconfig
$ sudoedit /etc/hosts

1.2.3.4 is my ip address and test.soivi and www.test.soivi are my domain names.

127.0.0.1       localhost
127.0.1.1       yourComputerName
1.2.3.4    test.soivi
1.2.3.4    www.test.soivi

# The following lines are desirable for IPv6 capable hosts
::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

Add file test.soivi in /etc/apache2/sites-available/

$ cd /etc/apache2/sites-available/
$ sudoedit test.soivi

This file tells where is the test.soivi’s index file. This is my directory “/home/user/public_html/” where my index file is.

<VirtualHost *:80>
        ServerName test.soivi
        ServerAlias www.test.soivi
        DocumentRoot "/home/user/public_html/"
</VirtualHost>

Enable site and reload Apache

$ sudo a2ensite test.soivi
$ sudo service apache2 reload

Now www.test.soivi and test.soivi domains works in your local computer.

$ firefox http://www.test.soivi/
$ firefox http://test.soivi/

Now you have virtual websites in your local computer.