How to create multiple local web host domain name with XAMPP in windows
Are you thinking to run your web site from your home pc using a custom domain (fake domain) name (eg. www.your-domain-name.com) instead of XAMPP ’s default URL like (http://localhost/my-site or something like that) or want to run multiple web sites from your home pc?
First of all I assure you that it is possible and quite easy. I assume you have installed XAMPP. Installing XAMPP allows you to develop, test, and play around with web server code on your local machine. You can configure and test out your website locally, instead of live somewhere on the web.
In my case, I've used
- XAMPP 3.2.1
- windows 7 64 bits
- Firefox 32.0.2
- I've installed XAMPP in E:\Installed\Xamp location.
By default XAMPP run your site from a default directory named htdocs. But you can changes this behavior of XAMPP by configuring Apache Server in XAMPP and windows hosts file.
This is a two step process: first, you have to redirect the web site name to your computer; next, you get Apache to redirect the web site address to a specific directory of your choice.
You may know that when we type a web site name into the URL field (eg. www.google.com), our browser sends the name to a Domain Name Server which actually convert the text name to ip address eg. www.google.com to10.11.201.71 (for example) then connects to IP address 10.11.201.71. Before doing that, it first checks a file called hosts on your computer. If the requested web site name is found, it uses the IP address found in the file. So first we will tell our browser to get our own (local) ip by changing the file host file. This file location is C:\Windows\System32\drivers\etc
Step 1. Configuring the windows’ hosts file
Open the file in any text editor. Go to the bottom of the file. You will find something like below image
Add your custom domain name below these line as in the below image. You can add as many domain names as you wish. See all are the same IP address
Update: it is better to add both version of domain with www and without www
eg. www.atshop.com and atshop.com
Step 2: configuring apache server’s virtual host file
Locate the “httpd-vhosts.conf” virtual host file. File location is in your XAMPP installation drive(c):\XAMPP \apache\conf\extra (in my case it is E:\Installed\Xamp\apache\conf\extra)
Open the file in a text editor and at the bottom of the file add this code by changing ServerName, ServerAlias,DocumentRoot as your needs.
<VirtualHost *:80> ServerName www.local.hiracave.com ServerAlias hiracave.com DocumentRoot E:/Installed/Xamp/htdocs/hiracave <Directory "E:/Installed/Xamp/htdocs/hiracave"> Order allow,deny Allow from all </Directory> </VirtualHost>
Remember if you have more than one site you need multiple copy of the code. See the bellow image for two website www.local.hiracave.com & www.canopas.com; I’ve added two piece of the code.
ServerName:following this label, add the name of the domain you added in windows hosts file.
ServerAlias:following this label, you may add the name without “www.” So that you can access your site using www.yoursite.com or only yoursite.com
DocumentRoot:following this label, add the path where your website is located.
Directory:This portion actually granting permission to access the directory you using. Otherwise you may encounter an ERROR 403
Save the file.
Restart the Apache Server to have the change take effect. Do this by clicking on the Stop button on the XAMPP control panel and then clicking on the Start button.
You are done. Now access your site using your domain name which you have setup just now. Your URL is www.your-domain-name.com. In my case it is www.local.hiracave.com and www.canopas.com also I can access my site using local.hiracave.com and canopas.com
In xampp 7.4 windows 10 there are some another configurations is required
Edit httpd-xampp.conf and httpd-vhosts.conf file as bellow tables hilighted part
Alias /licenses "C:/xampp/licenses/"
Alias /phpmyadmin "C:/xampp/phpMyAdmin/"
Alias /webalizer "C:/xampp/webalizer/"
I hope it will help you to understand how to create a single or multiple local web host domain name using XAMPP
If you have any query\comment please leave it in comment box. I'll be very pleased to reply you. Thank you.
All post under category PHP