Apache 2.2 Virtual Host not working - apache

I'm trying to set up a virtual host for a local site - something I've done literally hundreds of times - but something's going wrong this time.
My files are in C:\wwwroot\TEMPLATESITE
I have the following in my hosts file (last in a list of similar hostnames that all work)
127.0.0.1 templatesite.localhost.com
I have the following VirtualHost set up in my httpd-vhosts.conf (again, alongside a handful of other, identically set up, working sites)
<VirtualHost *:80>
ServerAdmin webmaster#dummy-host2.
DocumentRoot c:\wwwroot\TEMPLATESITE
ServerName templatesite.localhost.com
ErrorLog logs/templatesite.-error_log
CustomLog logs/templatesite.-access_log common
</VirtualHost>
(I've tried both with and without a trailing slash on the DocumentRoot)
Yet, no matter what I try, no matter how many times I restart Apache, or my machine, when I type in templatesite.localhost.com I end up at the root of c:\wwwroot which is my localhost root.
I'm guessing the problem is in my hosts file since the logs don't have any attempts to even access TEMPLATESITE so it seems like the hosts file is failing back to the generic localhost.
In that light, here's my entire hosts file:
127.0.0.1 lmm.localhost.com
127.0.0.1 lmm2.localhost.com
127.0.0.1 prairie.localhost.com
127.0.0.1 pinegrove.localhost.com
127.0.0.1 cas-pc.localhost.com
127.0.0.1 lksu.localhost.com
127.0.0.1 localhost
127.0.0.1 templatesite.localhost.com
Thoughts?

Related

Virtual hosts for MAMP 4.1.1 on MAC 10.12.6 not working

I know this has been asked hundreds of times and I made sure I read all of them, but still I cannot get this working. So as the title suggests, I cannot get a vhost running from MAMP/OSX. Here's a list of things I tried so far:
Created configuration in /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf
<VirtualHost *:80>
DocumentRoot /Applications/MAMP/htdocs
ServerName localhost
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "/Applications/MAMP/htdocs/abcd/public"
ServerName abcd.dev
ServerAlias www.abcd.dev
</VirtualHost>
Removed comment from the line
Include /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf
in the file /Applications/MAMP/conf/apache/httpd.conf
Finally this is how my /etc/hosts file looks
127.0.0.1 localhost
255.255.255.255 broadcasthost
::1 localhost
fe80::1%lo0 localhost
127.0.0.1 abcd.dev
Restarted MAMP and here are the test results:
http://localhost/ - Shows Index of and then /abcd
http://127.0.0.1/ - Shows Index of and then /abcd
abcd.dev - Unable to connect, Firefox was unable to connect to the server abcd.dev
Surprisingly
ping abcd.dev - Returns response 64 bytes from 127.0.0.1: icmp_seq=0 ttl=64 time=0.053 ms
ping 127.0.0.1 and ping localhost also returns same response.
I had docker running on my computer, I thought that was messing it up, so I stopped in completely, but the problem continues.
Any help is appreciated.
you have specified "www." prefix in your vhosts file, but tried to access is through abcd.dev (without the www.)
abcd.dev is now officially a public domain. So basically my browser is trying to locate the site "out there".
Instead let's use something like abcd.local or abcd.loc
Hope this helps someone stuck in .dev labyrinth.

Enabling virtual hosts in Apache makes every host forbidden (403)

I am on Windows 8 and just now installed Wamp 2.5 (Apache 2.4.9) at C:/wamp to test my code locally. I have my source code repository at D:/workpace/project1 which I manage using GIT (GIT is one of the reasons I don't want to disturb its location).
After Installing Wamp, I just went on to enable virtual hosts by uncommenting the following line in httpd.conf.
#Include conf/extra/httpd-vhosts.conf
Then I headed to conf/extra/httpd-vhosts.conf created its backup and created the virtual host.
<VirtualHost *:80>
ServerAdmin admin#example.com
DocumentRoot "D:/workspace/project1/"
ServerName project1
ServerAlias p1
ErrorLog "logs/project1(local)-error.log"
CustomLog "logs/project1(local)-access.log" common
<Directory "D:/workspace/project1/">
Require all granted
</Directory>
</VirtualHost>
Also edited the hosts file and added the necessary lines.
127.0.0.1 project1
127.0.0.1 p1
The problem is that I get 403 Forbidden error not just when I access project1/ and p1/, but also when I access localhost/.
When I disable httpd-vhosts.conf in httpd.conf by commenting out,
Include conf/extra/httpd-vhosts.conf
I am able to access localhost/ but as expected, project1/ and p1/ too resolve to localhost/.
Surprisingly, when I re-enable httpd-vhosts.conf in httpd.conf and restore the backup of original(unchanged) httpd-vhosts.conf, I still get 403 (Forbidden) even on localhost/. But again when I disable httpd-vhosts.conf, localhost/ comes to normal.
It is furthermore surprising to note that If I change DocumentRoot to a dummy folder within c:/wamp/www, the story is the same. So this is not just happening when DocumentRoot is outside c:/wamp/www.
I feel that I have something extra to enable because there is no chance I have messed up anything as this is a fresh installation and I have made no changes except the ones above.
What may be the reason Apache is not getting along with virtual hosts?
There are a few things that you have not taken into account.
When you create Virtual Hosts Apache ignores the host defined in httpd.conf so you also need to create a Virtual Host for localhost. This explains why you cannot get to localhost when you have activated Virtual Hosts.
Apache is IPV4 and IPV6 aware, so when you create your domain names in the HOSTS file you need to do so for both the IPV4 and IPV6 stacks. So you would need to have a HOSTS file like this :-
#IPV4 Stack
127.0.0.1 localhost
127.0.0.1 project1
#IPV6 Stack
::1 localhost
::1 project1
The browser makes some arbitrary decision on whether to use the IPV4 stack or the IPV6 stack. Wish I understood why and for what reason it makes this decision better, but basically when you enter a domainname, the browser, or the networking stack, picks IPv4 or IPv6 for your first contact to a domain and then sticks to that decision, but it could use either.
Here is a post that should help you create Virtual Hosts

Google Chrome virtual hosts not working with ERR_NAME_NOT_RESOLVED error after update

I started getting this error for all my local virtual hosts on apache in the morning when I updated my Chrome to the latest version on ubuntu.
While all of them work on other browsers chrome started misbehaving with ERR_NAME_NOT_RESOLVED error.
Screen shot for the error
Got it fixed like this:
Clear up the Chrome's DNS cache by typing this in the Chrome browser
chrome://net-internals/#dns
Screenshot -> Flushing Chrome DNS cache
You will see a button "Clear Host Cache". Press that DNS cache
will be flushed.
Keep this DNS window open. Now access the virtual host in the browser
for me it was http:/api.localhost. Once you do that you will see a
new entry in the DNS window. for me it was "localhost."
notice the period "." at the end of localhost that showed an error.
Last step is to simply add this entry as
127.0.0.1 localhost.
in the hosts file located at
for ubuntu : /etc/hosts
for windows : C:\Windows\System32\drivers\etc\hosts
Another solution could be to ditch the .localhost /.dev at the end of your local virtual host domain
This has to do with some new changes by google. ".dev" and ".local" comes under google's TLD (In the corner of the internet where people care about DNS, there is a bit of an uproar at Google's application for over a hundred new top-level domains, including .dev etc)
Use a domain name you own. Possibly using the full name like "localhost.dev.$yourdomain" could help here on the setup.
Here is how to fix xampp virtual hosts in chrome and firefox that are ending with .dev. who doesn't work anymore (in most versions of chrome, since .dev is real domain registered and reserved from google - [Dev domain ICANN]).
I had so much trouble, with getting virtual hosts working properly
on both firefox and chrome, but at the end i find out that the best solution
is to make two different hosts for each local domain. So i ended up with something like: Here is hosts file in (C:\Windows\System32\drivers\etc\hosts):
This is needed, becouse if you still want your localhost alive
127.0.0.1 localhost.
::1 localhost.
fe80::1%lo0 localhost.
This works fine in Firefox.
127.0.0.1 laravel.dev
::1 laravel.dev
fe80::1%lo0 laravel.dev
This works perfectly on Chrome.
127.0.0.1 laravel.localhost
::1 laravel.localhost
fe80::1%lo0 laravel.localhost
And here is my xampp httpd-vhosts.conf
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot "D:/xampp/htdocs/"
ServerName localhost
ServerAlias localhost
</VirtualHost>
<VirtualHost *:80>
ServerAdmin webmaster#laravel
DocumentRoot "D:/xampp/htdocs/laravel/public/"
ServerName laravel.dev
</VirtualHost>
<VirtualHost *:80>
ServerAdmin webmaster#laravel
DocumentRoot "D:/xampp/htdocs/laravel/public/"
ServerName laravel.localhost
</VirtualHost>
<VirtualHost *:80>
ServerAdmin webmaster#testsite
DocumentRoot "D:/xampp/htdocs/testsite/"
ServerName testsite.dev
</VirtualHost>
<VirtualHost *:80>
ServerAdmin webmaster#testsite
DocumentRoot "D:/xampp/htdocs/testsite/"
ServerName testsite.localhost
</VirtualHost>
I hope this helps for someone, because i lost a couple hours, finding out the best solution, and make the things work. :)
tags - virtual host doesn't work on chrome.
Another option is to replace in your file /etc/hosts any entry defined as your_domain.localhost with something like local.your_domain. But this would also require you to change the "ServerName" and "ServerAlias" value in your virtual hosts files.
For me is working this:
In hosts:
127.0.0.1 localhost.
::1 localhost.
fe80::1%lo0 localhost.
And In httpd.conf:
<VirtualHost localhost>
DocumentRoot "D:/Apache/htdocs/projects/some-project-root"
ServerName some-project.localhost
</VirtualHost>
Important is write to VirtualHost tag "localhost", "127.0.0.1" does not works in chrome.

VirtualHosts loading blank pages in Mavericks

I'm having issues loading VirtualHosts I've setup on my iMac, all that they appear to be returning are blank pages. I've tried multiple browsers, flushed my DNS cache, cleared browser cache etc but nothing appears to be fixing this.
Here is what my /etc/apache2/httpd-vhosts/conf file looks like:
NameVirtualHost *:80
<Directory "/Users/chris/Sites/test/">
Allow From All
AllowOverride All
</Directory>
<VirtualHost *:80>
ServerName "test.dev"
ServerAlias "test.dev.*.*.*.*.xip.io"
DocumentRoot "/Users/chris/Sites/test"
</VirtualHost>
Here is what my /etc/hosts file looks like:
##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
##
127.0.0.1 localhost
255.255.255.255 broadcasthost
::1 localhost
fe80::1%lo0 localhost
# VHX START
127.0.0.1 test.dev
fe80::1%lo0 test.dev
# VHX STOP
In my /private/etc/apache2/httpd.conf file I've made sure to uncomment the following line:
Include /private/etc/apache2/extra/httpd-vhosts.conf
I'm using VirtualHostX to manage all of this but I've even resorted to deleting everything in these files and starting again following guides online – that didn't work either.
I've tried to tail the apache access log and whenever I try to access http://test.dev nothing shows up in that file or the apache error log – it's as though my machine has absolutely no idea that URL exists even though I believe everything is setup correctly.
Any ideas on how I can fix this?
Thanks,
Chris

creating Subdomain in Xampp doesn't work

I made a subdomain on Localhost over Xampp with following code in httpd-vhosts.conf (guide from different sources)
NameVirtualHost *:80 (uncommented by removing #)
<VirtualHost *:80>
DocumentRoot C:/xampp/htdocs
ServerName localhost
</VirtualHost>
<VirtualHost *:80>
DocumentRoot C:/xampp/htdocs/sub
ServerName sub.localhost.com
</VirtualHost>
and following code into hosts of Windows/System32/drivers/etc/
127.0.0.1 localhost
127.0.0.1 sub.localhost
now the problem is subdomains are not working. One more thing I just noticed that when I start apache service in Xampp Control Panel, it has set the port as 80,443 for Apache which is good but as soon as I hit localhost in browser it changes port to different ports like 52352 etc. I also tried to setting up code in hosts file as
127.0.0.1:80 localhost
127.0.0.1:80 sub.localhost
but not working. I tried many other things but all in vein. While a month before I created successfully in the same Xampp Installation. off course i have created sub directory in htdocs.
Make sure you have this line uncommented in httpd.conf
#Include conf/extra/httpd-vhosts.conf
Remove this line in httpd-vhosts.conf (or comment it out):
NameVirtualHost *:80
Make sure you have a blank line at the end of both httpd-vhosts.conf and hosts, and make sure you're using tabs to separate IPs with their associated domains in the hosts file.
Make sure another application is not using ports 80, 443 (Skype for example).
Ultimately, restart your Apache server.
If you want to create sub directory, *emphasized text*127.0.0.1:80 localhost*emphasized text*
the settings back to original and change only *emphasized text*DocumentRoot C:/xampp/htdocs/sub*emphasized text*