How to Create Virtual Host in Apache on Ubuntu Debian and Linux Mint?

 Virtual Hosting helps you to run multiple domains on a single server. Shared hosting servers allow you to host thousands websites  on a single server using this Virtual Hosting. Today in this article i have listed the steps to run this Virtual hosting on Apache2 server on Ubuntu, Debian and Linux Mint systems.

Step 1: Installation of Apache:

To run this virtual host you should have apache in your system, Follow the below step to install apache in your system. If you have already installed apache in your system then you can skip this step.

$ sudo apt-get update

$ sudo apt-get install apache2

Step 2: Creating Your First Virtual Host:

All kind of virtual host configuration is stored under /etc/apache2/sites-available directory. You can find default virtual host file during the new apache installation. And create new virtual Host configuration file by copying default file.

$ cd /etc/apache2/sites-available/

$ sudo cp default

Edit the new virtual host configuration file and update as per your requirement.

For example i have taken

So type the following command.

$ vim

You will find the configuration file of above domain like this.

<VirtualHost *:80>



DocumentRoot /var/www/

<Directory />

Options FollowSymLinks

AllowOverride None


<Directory /var/www/>

Options Indexes FollowSymLinks MultiViews

AllowOverride None

Order allow,deny

allow from all


ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/

<Directory "/usr/lib/cgi-bin">

AllowOverride None

Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch

Order allow,deny

Allow from all


ErrorLog ${APACHE_LOG_DIR}/error.log

LogLevel warn

CustomLog ${APACHE_LOG_DIR}/access.log combined


And now create a directory structure in your system, as per defined in the above virtual host and assign owner ship and file permission.

$ mkdir -p /var/www/

$ chmod 755 /var/www/

$ chown www-data.www-data /var/www/

Now upload the project files on /var/www/ directory. For this example i have created a index.html file for testing purpose like below.

$ echo “<h1></h1> /var/www/

Step 3: Enabling the virtual Host

Now we have created our virtual host in apache. To enable the virtual the virtual host. When you reload, Apache will load the configuration file.

$ a2ensite

When you execute the above command soft link of Virtual Host configuration file is created in /etc/apache2/sites-enabled/ directory.

To activate the new configuration run the following command.

$ service apache2 reload

Now your new domain will be enabled and you can access in your browser. If you don’t have dns configured for your domain, do a local mapping by adding an entry in /etc/hosts files.



You can create still more virtual host by repeating the Step 2 and Step 3.


4:04 pm