1. About Virtual Hosts
Virtual Hosts are used to run more than one domain off of a single IP address. This is especially useful to people who need to run several sites off on one virtual private server. The sites display different information to the visitors, depending on with which the users accessed the site.There is no limit to the number of virtual hosts that can be added to a VPS.
2. Set Up
> sudo su
> apt-get install apache2
3. Create a new directory
The first step in creating a virtual host is to a create a directory where we will keep the new website’s information.
> mkdir –p /var/www/example.com/public_html
4. Grant Permission
We need to grant ownership of the directory to the user, instead of just keeping it on the root system.
> chown –R $USER:$USER /var/www/example.com/public_html
> chmod –R 755 /var/www
5. Create the Page
> nano /var/www/example.com/public_html/index.html
We can add some text to the file so we will have something to look at when the IP redirects to the virtual host.
<h1>Success: You have Set Up Virtual Host </h1>
Save and Exit.
6. Create the New Virtual Host File
> cp /etc/apache2/sites-available/default /etc/apache2/sites-available/example.com
7. Turn On Virtual Hosts
> nano /etc/apache2/sites-available/example.com
Activate the host, with the built in apache shortcut
> a2ensite example.com
8. Restart Apache
> service apache2 restart
9. Setting Up the Local Hosts
> nano /etc/hosts
Happy to help you !!