How to create virtual host in ubuntu ??

images (1)

Virtual Host

Virtual host is used for run more then one domain of a single ip address.This is useful if you want to run multiple sites using single ip address.

There is not limit to setup virtual host on VPS.

In this tutorial, we show how to setup virtual host in ubuntu server.

Now, proceed to setup virtual hosts/directory in Apache server.

Setup Virtual Hosts 

  1. Create Virtual Directories for virtual host data

    Now, proceed to setup different virtual host in single server. I want to create different virtual hosts “virtualdomain1.com” and “virtualdomain2.com”.First create directory for “virtualdomain11.com” host:
  2. Create a directory for “virtualdomain2.com” host:
  3. Set Ownership Permissions

    The above host directories are created by root user, so We need to change the ownership of these host directories to the normal user.

     
  4. Set Read Permissions
    Set read permissions to root directory(/var/www/html/), so everyone can read files.

     
  5. Add welcome pages for Virtual Hosts

    Now, we have to create the welcome pages to be access through the websites.

    First, we have to create a welcome page for the virtualdomain1.com virtual host.

    Add a ‘index.html’ file for virtualdomain1.com host,

    Similarly, add a welcome page for virtualdomain2.com host.

    Create ‘index.html’ file for virtualdomain2.com welcome page,

     

  6. Add virtual host data in Virtual Host Files

    Default, In Apache default virtual host file called 000-default.conf. We will add new virtual host data in this file.Now, add the virtualdomain1.com values in 000-default.conf files.sudo vi /etc/apache2/sites-available/000-default.confVirtual host of virtualdomain1:

    Virtual host of virtualdomain2:

     

  7. Add virtual domain names
    Edit file /etc/hosts,

    Add the virtual domain names as shown below :

    Save and close host file.

    Test created vitual hosts
    Open up your browser and enter the URL http://virtualdomain1.com or http://virtualdomain2.com. You will see the welcome pages which we have created earlier.