How to enable Virtual Host on Xampp for Laravel? - apache

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.

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>

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

Related

Serving multiple root directories in Apache

I would like my two sites: flowers.loc (Drupal 8) and honey.loc (Drupal 7) sites to work locally on Apache (v: 2.234).
First directory for flowers.loc:
Sites/drupal8/docroot
Second directory for honey.loc:
Sites/drupal7/docroot
I have this setting in httpd, apache configuration file:
<VirtualHost *:80>
DirectoryIndex index.html index.php
DocumentRoot /User/Vizzaro/Sites
<Directory "/User/Vizzaro/Sites">
Options FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
Have a look at https://httpd.apache.org/docs/2.2/vhosts/examples.html to find out how to set up virtual hosts. Your configuration file has only one virtual host entry but you need one entry for each site. And furthermore your config is missing the ServerName. Try this: (untested)
# Ensure that Apache listens on port 80
Listen 80
# Listen for virtual host requests on all IP addresses
NameVirtualHost *:80
<VirtualHost *:80>
ServerName flowers.loc
DocumentRoot /User/Vizzaro/Sites/drupal8/docroot
# Other directives here
</VirtualHost>
<VirtualHost *:80>
ServerName honey.loc
DocumentRoot /User/Vizzaro/Sites/drupal7/docroot
# Other directives here
</VirtualHost>
And be sure that honey.loc and flowers.loc both point to the IP of the machine on wich your apache is running. Try ping flowers.loc - if this results in an error like Name or service not known you probably have to edit your hosts file to fix it.

XAMPP Virtual Hosts not working

Before marking this as answered, please read the entire thing because yes there is a good amount of these questions but NONE of the answers on them have worked at all.
For the last 6 months I've looked at around 50 different form posts here and around the web to try and get my XAMPP virtual hosts working.
Hosts File
127.0.0.1 localhost
127.0.0.1 vws.localhost
127.0.0.1 instancegaming.net
127.0.0.1 vws.instancegaming.net
http-vhosts File (Updated 7/26)
# 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 *:80>
ServerName localhost
DocumentRoot "C:\xampp\htdocs"
<Directory "C:\xampp\htdocs">
DirectoryIndex index.php
</Directory>
</VirtualHost>
I'm at a loss of what to do, I've tried putting all fields to localhost then to instancegaming.net but nothing seems to work. I've read the Apache log and there's only SSL errors floating around.
When I try going to [ http:// ] vws.localhost, vws.192.168.0.47, vws.instancegaming.net all of which give the same error in chrome:
ERR_NAME_NOT_RESOLVED
Then I tried emptying chromes host cache, but that didn't help either.
Sidenote: I reinstalled XAMPP 4 times trying to make this work.
Follow these steps if you are in windows environment (7 & 10 tested) with XAMPP:
Add in hosts file [C:\Windows\System32\drivers\etc]
127.0.0.1 vws.localhost
127.0.0.1 instancegaming.net
127.0.0.1 vws.instancegaming.net
Add this in httpd.conf [C:\__Server\apache\conf] . though some says there are security risks with this but couldn't find a way without this
<Directory />
AllowOverride none
Require all granted
</Directory>
Add these in httpd-vhosts.conf [C:\__Server\apache\conf\extra]
<VirtualHost *:80>
ServerName localhost
DocumentRoot "C:\__Server\htdocs"
<Directory "C:\__Server\htdocs">
DirectoryIndex index.php
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName tools.com.at
DocumentRoot "E:\phpStorms\git\tools-class"
SetEnv APPLICATION_ENV "development"
<Directory "E:\phpStorms\git\tools-class">
DirectoryIndex index.php
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName laravel.test.com.at
DocumentRoot "E:\laravel.test.com.at\public"
SetEnv APPLICATION_ENV "development"
<Directory "E:\laravel.test.com.at\public">
DirectoryIndex index.php
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
template of this
<VirtualHost *:80>
ServerName nameInHostsFile
DocumentRoot "pathOfTheWindowsFileLocationWhichWillBeDocumentRoot"
SetEnv APPLICATION_ENV "development"
<Directory "pathOfTheWindowsFileLocationWhichWillBeDocumentRoot">
DirectoryIndex index.php
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
Note 1: My xampp installed on C:\__Server location
Note 2 : My folder name is laravel.test.com.at and its in E: drive E:\laravel.test.com.at
Note 3: Always copy folder location from address bar in windows explorer, so there is no mistakes.
Note 4: You must restart XAMPP after editing httpd-vhosts.conf every time.
Note 5: Use uncommon part in url [i.e .com.at] so that it is unique and there is no issue resolving dns.
Update: troubleshoot#Jacob Jewett
After a fresh copy of XAMPP installation in C drive -
just add/append these line in httpd-vhosts.conf file
<VirtualHost *:80>
ServerName localhost
DocumentRoot "C:\xampp\htdocs"
<Directory "C:\xampp\htdocs">
DirectoryIndex index.php
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName vws.localhost
DocumentRoot "C:\xampp\vws"
SetEnv APPLICATION_ENV "development"
<Directory "C:\xampp\vws">
DirectoryIndex index.php
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
Add append this in httpd.conf file
<Directory />
AllowOverride none
Require all granted
</Directory>
ADD PATH variable for php [C:\xampp\php], and also check that there isn't another php path in the PATH variable.
restart xampp and browse localhost
Additionally make sure that the line
Include etc/extra/httpd-vhosts.conf
is not quoted out in httpd.conf
The answer I found that works is to to this in the hosts file.
192.168.0.47 localhost somthing.instancegaming.net
One thing I'd like to add here: For anyone who is sure everything is setup correctly, make sure you don't use any underscores in the alias string within your hosts file; for some reason it can't accept underscores.
I have similar issue, vhosts not working. But in my case I found there was the permission issue with host file. Hope this helps for some one. hosts file ignored, how to troubleshoot?
If pings are successful but a Virtual Host is not working with XAMPP 7.3.1 and Windows 10 Pro the problem may be interference with the World Wide Web Publishing Service.
On my system, Apache and MySQL start successfully but the virtual host cannot be browsed till I stop the WWWPS service (in Windows Services). The virtual host then becomes instantly available. It instantly stops working when the WWWPS is started again.
I fixed the problem by just restarting my computer after setting up the System32 file hosts and the apache vhosts.

VirtualHost in Apache 2.4 replaces DocumentRoot when using http://localhost

I'm using Yosemite with Apache 2.4
/private/etc/apache2/httpd.conf
ServerName 127.0.0.1:80
DocumentRoot "/Library/WebServer/Documents/"
<Directory "/Library/WebServer/Documents">
Options Multiviews FollowSymLinks
MultiviewsMatch Any
AllowOverride All
Order allow,deny
Allow from all
</Directory>
Everything is fine, http://localhost directs me to the default /Library/WebServer/Documents/index.html
After adding Include /private/etc/apache2/extra/httpd-vhosts.conf to /private/etc/apache2/httpd.conf
And adding the config below to /private/etc/apache2/extra/httpd-vhosts.conf
<VirtualHost *:80>
ServerAdmin admin#xxx.com
ServerName xxx.local
DocumentRoot "/Library/WebServer/Documents/xxx"
<Directory "/Library/WebServer/Documents/xxx/">
Options +FollowSymLinks
AllowOverride all
Require all granted
</Directory>
</VirtualHost>
When using http://localhost and http://127.0.0.1 from the browser, Apache directs me to /Library/WebServer/Documents/xxx/index.html instead of /Library/WebServer/Documents/index.html, how can I fix it?, please guide.
Thanks.
I had the same problem today.
I found solution here: httpd.apache.org/docs/current/vhosts/name-based.html.
Main host goes away
Any request that doesn't match an existing is handled by the global server configuration, regardless of the hostname or ServerName.
When you add a name-based virtual host to an existing server, and the virtual host arguments match preexisting IP and port combinations, requests will now be handled by an explicit virtual host. In this case, it's usually wise to create a default virtual host with a ServerName matching that of the base server. New domains on the same interface and port, but requiring separate configurations, can then be added as subsequent (non-default) virtual hosts.

Wampserver shows 404 errors after swapping to using Vhosts

So I was using Wampserver for developing purposes, and I managed to set up the server for developing purposes (it worked with Dreamweaver, PHP worked etc.) but when accessing localhost, I get a 404 error.
I've hardly changed the settings, other than setting it to use that vhosts file, then I made a few new hosts in the hosts file in system 32, which all works fine.
localhost/phpmyadmin does work, however, so I am really stumped as to why it won't load anything. I also tried loading one of the site folders (localhost/Rufus) which also returned a 404. I have all the directories I need pointing to www folder, where all my files are saved.
And before anyone says, no it's not Skype or IIS, as they are both off and Wampserver is running on port 80 (I checked)
My vhosts file:
# 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.
#
# 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 *:80>
ServerAdmin webmaster#dummy-host.example.com
DocumentRoot "c:/Apache24/docs/dummy-host.example.com"
ServerName dummy-host.example.com
ServerAlias www.dummy-host.example.com
ErrorLog "logs/dummy-host.example.com-error.log"
CustomLog "logs/dummy-host.example.com-access.log" common
</VirtualHost>
<VirtualHost *:80>
ServerAdmin webmaster#dummy-host2.example.com
DocumentRoot "c:/Apache24/docs/dummy-host2.example.com"
ServerName dummy-host2.example.com
ErrorLog "logs/dummy-host2.example.com-error.log"
CustomLog "logs/dummy-host2.example.com-access.log" common
</VirtualHost>
<Directory C:\Users\Tom\sites\wamp\www>
Order Deny,Allow
Allow from all
</Directory>
<VirtualHost *:80>
DocumentRoot "C:\Users\Tom\sites\wamp\www\Rufus"
ServerName rufus.stone
</VirtualHost>
Remove the sample virtual hosts, assuming you aren't using them. You also need a virtual host for 'localhost' and it must be the first virtual host. After that you can include your other, custom vhosts.
#
# Use name-based virtual hosting.
#
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot "C:\Users\Tom\sites\wamp\www"
ServerName localhost
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "C:\Users\Tom\sites\wamp\www\Rufus"
ServerName rufus.stone
</VirtualHost>
If you get a permission denied error try putting the directive I took out into your httpd.conf:
<Directory "C:\Users\Tom\sites\wamp\www">
Order Deny,Allow
Allow from all
</Directory>
It would go right under a similar directive that includes a Deny from all on the root.
Make sure you always restart Apache whenever you make changes to these files.
The error 404 is saying that you have not granted access to those Virtual Hosts, so Apache is kicking you out.
You need to include with your Virtual Host some information to tell Apache which locations are allowed access to each VHOST
You also need to make localhost a Virtual Host and because the first VHOST is the default VHOST it should really be the first you define, and it should always be limited to allow access only from the local machine.
So see if this works any better.
# Virtual Hosts
#
<VirtualHost *:80>
DocumentRoot "C:\Users\Tom\sites\wamp\www"
ServerName localhost
<Directory "C:\Users\Tom\sites\wamp\www">
AllowOverride All
Require local
</Directory>
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "C:\Users\Tom\sites\wamp\www\Rufus"
ServerName rufus.stone
<Directory "C:\Users\Tom\sites\wamp\www\Rufus>
AllowOverride All
Require local
</Directory>
</VirtualHost>
Require local says allow access from the PC running WAMPServer only.
If later you want to allow other PC's on your internal network to see the Apache server you can add to that like this, for example.
Require local
Require ip 192.168.1
This, assuming you are on the subnet 192.168.1.? will allow any PC connected to your router (wired or wifi) access to the server.
You should avoid these, unless you actually want the world to access your site
Require all granted
OR the Apache 2.2 syntax, which still works on Apache 2.4
Order Deny,Allow
Allow from all

error setting virtualhosts in xampp

I have read a lot of articles and posts about Virtual Hosts setting but I was not able to figure out which is the problem.
I have a Win7 pc where I installed an xampp to manage my php + mysql projects.
As per default the web root directory is C:\xampp\htdocs
To avoid conflict with skype I setted apache to work on port 8080
If I browse to something like localhost:8080/mysubdir it works fine.
My idea was now to point the webroot of Apache to another dir on my pc: the dir where I would like to point my webroot is C:\Users\myuser\Google Drive\CODE_REPOS
I searched on-line and it seems to be possible by VirtualHost;
Here my configuration
apache httpd.conf
#Listen [::]:80
Listen *:8080
# Virtual hosts
#Include "conf/extra/httpd-vhosts.conf"
here my httpd-vhosts.conf
# Use name-based virtual hosting.
#
NameVirtualHost *:8080
#
# 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 *:8080>
ServerAdmin admin#localhost.com
DocumentRoot "C:/xampp/htdocs" # change this line with your htdocs folder
ServerName localhost
ServerAlias localhost
<Directory "C:/xampp/htdocs">
Options Indexes FollowSymLinks Includes ExecCGI
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
<VirtualHost development.loc:8080>
ServerAdmin admin#localhost.com
DocumentRoot "C:/Users/myuser/Google Drive/CODE_REPOS" # change this line with your htdocs folder
ServerName development.loc
ServerAlias development.loc
<Directory "C:/Users/myuser/Google Drive/CODE_REPOS">
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
Now the code in C:\Windows\System32\drivers\etc\hosts
# localhost name resolution is handled within DNS itself.
# 127.0.0.1 localhost
# ::1 localhost
127.0.0.1 localhost
127.0.0.1 development.loc
If I stop Apache, uncomment the line #Include "conf/extra/httpd-vhosts.conf" and try to start Apache again, it start and stop immediatly.
I don't understand what I missed.
remove the hash from the start of the include line
apache httpd.conf
#Listen [::]:80
Listen *:8080
# Virtual hosts
include "conf/extra/httpd-vhosts.conf"