Set Up Virtual Host on Ubuntu




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.

  1. Set Up

>  sudo su

>  apt-get install apache2

  1. 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/

  1. 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/

>  chmod –R 755 /var/www

  1. Create the Page

>  nano /var/www/

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.

  1. Create the New Virtual Host File

>  cp /etc/apache2/sites-available/default /etc/apache2/sites-available/

  1. Turn On Virtual Hosts

>  nano /etc/apache2/sites-available/

<VirtualHost *:80>




DocumentRoot /var/www/

Activate the host, with the built in apache shortcut

>  a2ensite

  1. Restart Apache

> service apache2 restart

  1. Setting Up the Local Hosts

>  nano /etc/hosts


#Virtual  Hosts 


Add a Comment

Your email address will not be published. Required fields are marked *