setup Virtual Hosts with XAMPP for Windows Users

XAMPP virtual hosts setup is quite easy. There are some reasons to use virtual hosts. Although, your XAMPP works fine if you don’t configure virtual hosts. To use custom domain / virtual hosts, you must designate the IP address or (Port, if available). Lets have a look why do we need to create virtual hosts at local server.

Reasons – Creating virtual hosts

  • Test your web projects on local server as same as original domain name.
  • To work at 2 or more domains.
  • Maintain your web projects with the name.
  • Good for absolute path (I personally create for this reason).

Step #1 – Assign Hosts Name

Windows have a file with the name of “hosts” which can be located at “C:\Windows\System32\drivers\etc\”. Let put your local server IP which usually defined already “127.0.0.1″. Start with the local IP and place “space or tab” to define virtual hosts / domain name. See Figure #1.

127.0.0.1    localhost
127.0.0.0    yourdomain.com
127.0.0.1    anotherdomain.tk

virtual-host-2
virtual-host-2
Tip: Before update the “hosts” file you should check security permission of this file. Sometimes it detects read only mode or permission rights. Move “hosts” file at your Desktop, update it with your virtual hosts line and re-move it to original place.

Step #2 – Setting up virtual hosts in XAMPP

I am writing step by step, I hope it would be great for you.

  1. Explore your XAMPP Apache folder and find “httpd-vhosts.conf” at mentioned path “C:\xampp\apache\conf\extra”
  2. Open the file in text editor.
  3. Paste or write below lines into your Apache hosts file.
NameVirtualHost 127.0.0.1:80
<virtualhost 127.0.0.1:80>
DocumentRoot "C:/xampp/htdocs"
ServerName localhost
</virtualhost>
4.   Above lines assign localhost for htdocs folder (http://localhost/)
5.   Now the next lines will create a virtual hosts.
<virtualhost yourdomain.com:80>
DocumentRoot "C:/xampp/htdocs/domain1"
ServerName yourdomain.com
</virtualhost>
6.  Restart your XAMPP and open the domain (http://yourdoamin.com).
7.  It would be open your “domain1″ folder’s default web file

ayzeetech

I'm Ayaz Ahmed Mast, I am a web developer and Instructor at Al Fateem Academy. My current weapons of choice are PHP CodeIgniter, jQuery, AJAX and Laravel. Being a Developer, I help clients bring their ideas into reality. Contact me today and I would love to hear about your business.

One thought on “setup Virtual Hosts with XAMPP for Windows Users

Leave a Reply

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