Online Snippets Library

Create Virtual Host in Xampp or Lampp on Linux

We creates virtual host for is a method for hosting multiple domain names on a single server (or multiple servers).In this process one server to share its resources like memory and processor cycles.

We will following step to create virtual host.

Step 1

Go to /opt/lampp/etc/httpd.conf And open httpd.conf.

Now search "#Include conf/extra/httpd-vhosts.conf" and remove "#" sign in front of "Include conf/extra/httpd-vhosts.conf".

Step 2

Open httpd-vhosts.conf file located in "/opt/lampp/etc/extra/httpd-vhosts.conf" and add following code.

<VirtualHost *:80>
DocumentRoot /opt/lampp/htdocs
ServerName localhost
ServerAlias www.localhost
#New Virtual host
<VirtualHost *:80>
DocumentRoot /opt/lampp/htdocs/localhost2
#path of your new host
ServerName localhost2
#name of your new host
ServerAlias www.localhost2
#alias of your new host
Step 3

Go to "/etc/hosts" and open the file "hosts" and add following line. localhost2 Step 4

Restart the Apache service

Now we have two virtual host in our computer. we can access it through following url. http://localhost //has document root /opt/lampp/htdocs http://localhost2 //has document root /opt/lampp/htdocs/localhost2