Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

xampp virtual host - always loading htdocs

I am trying to create a virtual host on my localhost (XAMPP). Tried every combination out there, but I always get htdocs loaded instead of the specific folder

Here is the hosts file:

127.0.0.1 localhost
::1 localhost
127.0.0.1 devsnappy

Here is httpd-vhosts.conf:

NameVirtualHost *:80
<VirtualHost *:80>
    DocumentRoot E:/xampp/htdocs/snappy/public
    ServerName devsnappy
    <Directory "E:/xampp/htdocs/snappy/public">
        Options Indexes FollowSymLinks Includes ExecCGI
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

Any suggestions?

like image 238
Wowzaaa Avatar asked Jul 16 '13 09:07

Wowzaaa


3 Answers

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 hosts
Include 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!

like image 133
TheKitMurkit Avatar answered Sep 28 '22 18:09

TheKitMurkit


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

like image 37
Armand Avatar answered Sep 28 '22 19:09

Armand


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.dev
127.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 [email protected]
    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 [email protected]
    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

http://postimg.org/image/5pug9f42p/

like image 20
Rocker Maruf Avatar answered Sep 28 '22 18:09

Rocker Maruf