xampp virtual host - always loading htdocs
For anyone who reads this and no solution help you, this is what helped me.
Just uncomment this Include line in your httpd.conf:
# Virtual hostsInclude etc/extra/httpd-vhosts.conf
That way, it will make changes you made in your etc/extra/httpd-vhosts.conf available!
Don't forget to restart Apache server afterwards!
Here is a guide to add vhost to xampp
Seems that you miss something with the hosts file.
For example, say you had another Web site for ClientB. You’d add 127.0.0.1 clientB.local >in the hosts file and the C:\xampp\apache\conf\extra\httpd-vhosts.conf would look like this:
NameVirtualHost * <VirtualHost *> DocumentRoot "C:\xampp\htdocs" ServerName localhost </VirtualHost> <VirtualHost *> DocumentRoot "C:\Documents and Settings\Me\My Documents\clientA\website" ServerName clientA.local <Directory "C:\Documents and Settings\Me\My Documents\clientA\website"> Order allow,deny Allow from all </Directory></VirtualHost><VirtualHost *> DocumentRoot "C:\Documents and Settings\Me\My Documents\clientB\website" ServerName clientB.local <Directory "C:\Documents and Settings\Me\My Documents\clientB\website"> Order allow,deny Allow from all </Directory></VirtualHost>
And restart httpd
Oh, It was really for painful for me to get it work in Apache 2.4.9.I found a lot of tutorials, but I can not make it work.
MY SOLUTION IS FOR APACHE 2.4 AND ABOVE VERSION.I have tested it with Apache 2.4.9
You need to edit two files.PLEASE MAKE BACKUP OF THIS TWO FILE BEFORE YOU MAKE CHANGES.If you write anything wrong , your localhost will not work even you uninstall xampp and then again install xampp.
STEP 1:
Edit this file
C:\Windows\System32\drivers\etc\hosts
Open this file using "Run As Adminstrator" from Notepad(Very Important).You can do this by
Start Menu > Notepad >Right Click > Run As Adminstrator > Open file
add these two lines at the end of this file
127.0.0.1 testsite.dev127.0.0.1 www.testsite.dev
Either you go testsite.dev or www.testsite.dev , it will now try to access from your local machine NOT from the web
STEP 2:
E:\xampp\apache\conf\extra\httpd-vhosts.conf
You can edit this file normally , there is no need to run this file as "Run As Adminstrator"Add the follwing lines at the end of this file
NameVirtualHost *:80<VirtualHost *:80> DocumentRoot "E:/xampp/htdocs" ServerName localhost</VirtualHost><VirtualHost *:80> ServerAdmin admin@.testsite.dev DocumentRoot "E:/xampp/htdocs/htc" ServerName testsite.dev ServerAlias www.testsite.dev</VirtualHost>
I setmy xampp in E drive , so when you copy from here , make sure you change it according to your xampp installation.the Last part is little interesting.I am pointing out this potion
<VirtualHost *:80> ServerAdmin admin@.testsite.dev DocumentRoot "E:/xampp/htdocs/htc" ServerName testsite.dev ServerAlias www.testsite.dev</VirtualHost>
Where can you find this code?In internet , you can find it in many places but might not work for you as that code will differentiate from your Apache version.SO WHAT"S THE SOLUTION?
At the end of file , you will see there are some commented lines already to show you a demo how to setup virtual host, just copy those lines and make necessary changes and it will work for you.I have attached a screenshot for better understanding