14

I have XAMPP running on Windows 7 Pro. I am trying to setup a Virtual Host so that when I use "dev.app" as a domain I get directly to my public folder of laravel installation.

Laravel is located at F:/xampp/htdocs/dev/public

I opened the httpd-vhosts.conf file located at F:\xamp\apache\conf\extra\https-vhosts.conf

and replaced everything with this

# Virtual Hosts
#
# Required modules: mod_log_config

# If you want to maintain multiple domains/hostnames on your
# machine you can setup VirtualHost containers for them. Most configurations
# use only name-based virtual hosts so the server doesn't need to worry about
# IP addresses. This is indicated by the asterisks in the directives below.
#
# Please see the documentation at 
# <URL:http://httpd.apache.org/docs/2.4/vhosts/>
# for further details before you try to setup virtual hosts.
#
# You may use the command line option '-S' to verify your virtual host
# configuration.

#
# Use name-based virtual hosting.
#

NameVirtualHost *:80

#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for all requests that do not
# match a ##ServerName or ##ServerAlias in any <VirtualHost> block.
#

<VirtualHost localhost>
    DocumentRoot "F:/xampp/htdocs/"
    ServerAdmin admin@localhost

    <Directory "F:/xampp/htdocs/">
        Options Indexes FollowSymLinks
        AllowOverride all
    </Directory>

</VirtualHost>

# Development
<VirtualHost dev.app>
    DocumentRoot "F:/xampp/htdocs/dev/public"
    ServerAdmin admin@localhost

    <Directory "F:/xampp/htdocs/dev/public">
       AllowOverride All
       Order Allow,Deny
       Allow from all
       Require all granted
    </Directory>
</VirtualHost>

then I opened my hosts file located at C:\Windows\System32\drivers\etc and added changed the localhost line to look like this

127.0.0.1       localhost      dev.app
127.0.0.1       127.0.0.1

However, when I go to dev.app in my browser I get this error

Unable to connect

Firefox can't establish a connection to the server at app.dev.

The site could be temporarily unavailable or too busy. Try again in a few moments.
If you are unable to load any pages, check your computer's network connection.
If your computer or network is protected by a firewall or proxy, make sure that Firefox is permitted to access the Web.

What am I missing here? What did I do wrong?

Note: I restarted Apache after I change the vhosts file. Also, I updated the app.php file in the config folder of laravel to have http://dev.app value in the url.

UPDATED after adding http://.... the site resolve but the images are not showing.

2
  • 1
    I noticed sometimes you need to go to http://... on localhost or it won't work. Also make sure when you update any apache conf files, restart the webserver for the changes to take effect. Commented Aug 11, 2015 at 21:21
  • http:// is what really did it :) thank you But now the images are not resolving properly. I see the site with no images
    – Junior
    Commented Aug 11, 2015 at 21:24

2 Answers 2

21

The hosts file should look like this so that it can be found on the IPV4 and IPV6 networks

127.0.0.1  localhost dev.app
::1        localhost dev.app

If you are using Apache 2.4.x this line in httpd-vhosts.conf

NameVirtualHost *:80

is no longer required or allowed for Apache 2.4.

The vhost file should look like this, you mixed Apache 2.2 and 2.4 syntax and while either is allowed as long as you have mod_access_compat activated, you should not mix them and the 2.4 syntax is better. You also missed a few other useful bits and pieces

<VirtualHost *:80>
    DocumentRoot "F:/xampp/htdocs/"
    ServerAdmin admin@localhost
    ServerName localhost

    <Directory "F:/xampp/htdocs/">
       Options Indexes FollowSymLinks
       AllowOverride all
       Require local
    </Directory>
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot "F:/xampp/htdocs/dev/public"
    ServerAdmin admin@localhost
    ServerName dev.app
    ServerAlias www.dev.app

    <Directory "F:/xampp/htdocs/dev/public">
       AllowOverride All
       Options Indexes FollowSymLinks
       
       Require local
       # if you want access from other pc's on your local network
       #Require ip 192.168.1
       # Only if you want the world to see your site
       #Require all granted
    </Directory>
</VirtualHost>
6
  • This work for me. I have Apache 2.4.x and my 'https-vhosts.conf' file was with de Apache 2.2.x format. Thanks Commented Sep 15, 2015 at 23:59
  • 1
    httpd-vhosts.conf is the name of the file @PedroLoureiro Commented Jun 10, 2020 at 8:04
  • @sabertabatabaeeyazdi File name was mentioned in the answer, I just bolded it so it is not so easy to miss
    – RiggsFolly
    Commented Jun 10, 2020 at 10:03
  • It seems that starting on Chrome 63 all the urls containg .app redirects to https. I couldn't fine an official post from Google for .app domains. There is only documentation about .dev domains ma.ttias.be/chrome-force-dev-domains-https-via-preloaded-hsts I replaced mydomain.app with mydomain.test and this answer worked for me. Commented Jun 9, 2021 at 0:19
  • @Sagarppanchal This is an answer to a WINDOWS based question. Therefore there is NO sudo as its windows not ubuntu! Please be careful changing an answer, first read the context
    – RiggsFolly
    Commented Nov 7, 2022 at 13:11
0
open C:\xampp\apache\conf\httpd.conf, locate at
# Virtual hosts
#Include conf/extra/httpd-vhosts.conf, remove # in this line,
save file,
Restart server

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.