4

I try to set up virtual host for some local site with XAMPP.

I executed next steps:

  1. In "C:/xampp/apache/conf/extra/httpd-vhosts.conf" I added:
<VirtualHost *:8081>
    DocumentRoot "C:/xampp/htdocs/"
    ServerName localhost
</VirtualHost>
<VirtualHost *:8081>
    DocumentRoot C:/xampp/htdocs/fw/public
    ServerName fw.local.com
    <Directory "C:/xampp/htdocs/fw/public">
        DirectoryIndex index.php
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>
  1. Inside "C:/Windows/System32/drivers/etc/hosts" I added:
127.0.0.1       localhost    
127.0.0.1       fw.local.com
  1. Restarted Apache.

And...

If I follow to:

http://localhost:8081/

All is OK: I see my catalog with projects in folder "htdocs".

But! If I follow to:

http://fw.local.com/

I expect to see result of my "index.php" file inside "..htdocs/fw/public". But I get:

This site can’t be reached
fw.local.com refused to connect.

File "C:/xampp/apache/conf/httpd.conf" contains:

# Virtual hosts
Include conf/extra/httpd-vhosts.conf

Where I was wrong?

Raz0rwire
  • 686
  • 9
  • 18

1 Answers1

5

You should change: <VirtualHost *:8081> to <VirtualHost *:80> on both counts, fw.local.com attempts to connect to port 80, not 8081.

Edit: You could also keep it the way you have it and connect to: http://fw.local.com:8081/

Raz0rwire
  • 686
  • 9
  • 18
  • Thanks, @Raz0rwire! You are right. But in the global settings also need to change port from 80 to 8081 (I mean XAMPP) for my goal. Tell me please, if I need to use some exact port for Apache (not 80, for example 8081), can I create virtual host that I can go to "fw.local.com" without 8081? –  May 13 '17 at 15:47
  • You could reverse proxy, but that would be overkill, is there a specific reason for not running on port 80? – Raz0rwire May 15 '17 at 08:25
  • 1
    At this moment - no. Just I want to know it if it sometime is required to me. Anyway, many thanks! –  May 15 '17 at 18:15
  • 1
    If you want to run on 'just the domain' without specifying a port, you ar required to listen on :80, if you have ssl set up you are required to listen on :443 :) You're welcome, could you maybe accept my answer? – Raz0rwire May 15 '17 at 18:41
  • doesn't worked for me even I added custom port with url but getting `404` – Moeez Mar 11 '22 at 10:40