How to set up a Virtual Host locally with XAMPP/LAMPP in Ubuntu

Once in awhile, we need to create locally domain alias for our projects in XAMPP. In this article, we will see how to set up a Virtual host locally with XAMPP/LAMPP in Ubuntu.

Let’s consider a scenario you have project myproject in your htdocs folder and you want to access this project as on your local server/machine. If your goal is the same then tag along.

Step 1 – Create your host/ local domain name.

Open your terminal anywhere and type the following command.

sudo gedit /etc/hosts

This will open hosts.txt file. Next, you will add your host address with domain name alias. In the file there will be some content already do not mess with that, just add your one-line like below.	localhost 

# The following lines are desirable for IPv6 capable hosts
::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

On the second line I have added my custom hosts that will run on , you are free to use any IP address.

Step 2 – Create a virtual host and assign our directory path

Now on your terminal type the following command.

sudo gedit /opt/lampp/etc/extra/httpd-vhosts.conf

This will open up httpd-vhosts.conf file. What you have to do just go end of the file and add the following lines.

  DocumentRoot "/opt/lampp/htdocs/myproject"
  DirectoryIndex index.php
  <Directory "/opt/lampp/htdocs/myproject">
	Options All
	AllowOverride All
	Require all granted

Now that our domain is pointed to the corresponding directory.

Step 3 – Enable custom Virtual hosts configuration

On your terminal type the following command to enable the use of custom virtual hosts.

sudo gedit /opt/lampp/etc/httpd.conf

Now in httpd.conf go to the line number 488 and you will see #Include etc/extra/httpd-vhosts.conf just remove the hash(#) from the line.


#Include etc/extra/httpd-vhosts.conf


Include etc/extra/httpd-vhosts.conf

So that’s it. Now start your LAMPP server and test with on any browser. It will surely work.

That was all about how to set up a Virtual host locally with XAMPP/LAMPP in Ubuntu. This way you can create unlimited custom domain for each projects of htdocs.

I hope this article will help you. In case of any issues and query , leave your comment in below comments box section.


see also

Leave a Reply

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