user3686739
user3686739

Reputation: 31

Xampp Apache 2.4 VirtualHost not working

I have xampp with apache 2.4 on windows 10. i have this configuration in my C:\xampp\apache\conf\extra\httpd-vhosts.conf

<VirtualHost *:80>
   DocumentRoot "C:/xampp/htdocs"
   ServerName localhost
   ServerAlias www.localhost
</VirtualHost>
<VirtualHost *:80>
   DocumentRoot "C:/xampp/htdocs/site3/web"
   ServerName site3.localhost
   ServerAlias www.site3.localhost
</VirtualHost>
<VirtualHost *:80>
   DocumentRoot "C:/xampp/htdocs/site2/web"
   ServerName site2.localhost
   ServerAlias www.site2.localhost  
</VirtualHost>

I added in my hosts file:

127.0.0.1       site2.localhost 
127.0.0.1       site3.localhost
127.0.0.1       www.site2.localhost 
127.0.0.1       www.site3.localhost

When i browse http://site2.localhost i see xampp root index. When i browse http://site3.localhost i see again xampp root index.Same with www.site2.localhost...

What am I doing wrong?

Upvotes: 0

Views: 1224

Answers (1)

RiggsFolly
RiggsFolly

Reputation: 94672

A quick bit of info on Virtual Hosts. If you set one up and when you try and use it it sends you to the first Virtual Host, normally localhost it means there is something wrong with the Virtual Host definition or the HOSTS file, or you have entered the url incorrectly.

Apache will use the first VH defined in the file as the default site.

First remove these 2 lines from the HOSTS file

127.0.0.1       www.site2.localhost 
127.0.0.1       www.site3.localhost

The HOSTS file should look like this

127.0.0.1 localhost
127.0.0.1 site2.localhost 
127.0.0.1 site3.localhost

::1 localhost
::1 site2.localhost 
::1 site3.localhost

Now each Virtual Host definition should also include some access rights like this

<VirtualHost *:80>
   DocumentRoot "C:/xampp/htdocs/site3/web"
   ServerName site3.localhost
   ServerAlias www.site3.localhost
    <Directory  "C:/xampp/htdocs/site3/web/">
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Require local
    </Directory>
</VirtualHost>

<VirtualHost *:80>
   DocumentRoot "C:/xampp/htdocs/site2/web"
   ServerName site2.localhost
   ServerAlias www.site2.localhost  
    <Directory  "C:/xampp/htdocs/site2/web/">
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Require local
    </Directory>
</VirtualHost>

Upvotes: 1

Related Questions