WAMP Virtual Host not working

强颜欢笑 提交于 2019-11-28 06:35:16

First you need to remove the example dummy definitions from your vhost-httpd.conf file. They are there as examples only just to get you started with the syntax, and should not remain in an active conf/extra/httpd-vhosts.conf as they are pointing to non existant folders.

So remove these 2 definitions from the file:

<VirtualHost *:80>
    ServerAdmin webmaster@dummy-host.example.com
    DocumentRoot "g:/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 "g:/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>

Second Apache 2.4.x is IPV4 ( 127.0.0.1 ) and IPV6 (::1) aware so your hosts file should look like this with definitions for both IPV4 and IPV6 versions for each site. The browser can arbitrarily use either so you need both but will probably use the IPV6 network in preference to the IPV4 if both are actually active on your PC.

127.0.0.1   localhost
::1  localhost

127.0.0.1   mysite.dev
::1  mysite.dev

Now on the 2 Virtual Hosts that actually exist on your system try this as the Virtual Host definition :

<VirtualHost *:80>
    DocumentRoot "g:/wamp/www"
    ServerName localhost
    ServerAlias localhost
    ErrorLog "logs/localhost-error.log"
    CustomLog "logs/localhost-access.log" common
    <Directory  "G:/wamp/www">
        AllowOverride All
        Options Indexes FollowSymLinks
        Require local
    </Directory>
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot "g:\wamp\www\mysite\public"
    ServerName mysite.dev
    ServerAlias www.mysite.dev
    ErrorLog "logs/mysite-error.log"
    CustomLog "logs/mysite-access.log" common
    <Directory  "G:/wamp/www/mysite/public">
        AllowOverride All
        Options Indexes FollowSymLinks
        Require local
    </Directory>
</VirtualHost>

The <Directory>....</Directory> section within the <VirtualHost>....</VirtualHost> section tells Apache which IP Addresses it is allowed to accept connections from, so using the Apache 2.4 syntax Require local limits access so that only the PC running WAMPServer i.e. Apache can connect to any of these site.

Avoid mixing Apache 2.2 syntax and Apache 2.4 syntax together in the same definition. So dont use

Order Allow,Deny
Allow from all

and

Require all granted

in the same definition. You are using Apache 2.4 so use the Apache 2.4 syntax.

If you find you want to allow other PC's inside your local network to see you site i.e. work mate or the kids etc, you can add this syntax to one or more of your Virtual Host definition.

Allow just a single other PC into your site

Require local
Require ip 192.168.1.100

or 2 other PC's

Require local
Require ip 192.168.1.100, 192.168.1.101

Or to anyone on your local network just use the first 3 of the 4 quartiles of the ip address.

Require ip 192.168.1

Also avoid using the syntax that allows access from anywhere i.e.

Require all granted  <--Apache 2.4 syntax

or 

Order Allow,Deny     <-- Apache 2.2 syntax
Allow from all    

It may solve your issues in the short term, but is just waiting to catch you sometime later when you decide you want to show your site to a friend/client/boss. If you get to the stage of Port Forwarding you router so that the world is allowed into your network that would cause ALL OF YOUR SITES to become available to the world.

Better to change the ONE Virtual Host Definition for the ONE site you want people to see for testing/bragging from Require local to Require all granted and only allow that single site to be access from the internet.

Once you have made all these changes remember to restart Apache.

Also if you change the hosts file to make the chnages active you should either reboot or run these command from the command line of a command windows started ising the Runs as Administrator option.

net stop dnscache
net start dnscache

If you are using Windows 10 the above dns commands no longer work, you should do this instead.

ipconfig /flushdns

Due to Google acquiring .dev gTLD, having .dev development sites is no longer easily possible, best way to mitigate is to just rename your development domain into .local or something that you prefer.

What happens in the background is that the local DNS server redirects the browser to 127.0.53.53 (open cmd > nslookup yourdomain.dev) in order to inform end-users of .dev gTLD being acquired. Since the .dev domain in hosts file is set to 127.0.0.1 it shows connection refused.

You can change 127.0.0.1 to 127.0.53.53 in the hosts file and see that the browser error changes from ERR_CONNECTION_REFUSED to ERR_ICANN_NAME_COLLISION.

Mahesh Hegde

Following is working for me

<VirtualHost *:80>
    DocumentRoot "G:\project\test.dev"
    ServerAdmin test@gmail.com
    ServerName test.dev
    ErrorLog "logs/test.dev-error.log"
    CustomLog "logs/test.dev-access.log" common
    <Directory "G:\project\test.dev">
       AllowOverride All
       Options Indexes FollowSymLinks
       Require local
    </Directory>
</VirtualHost>

I fix the same problem by uncomment some lines in httpd.conf in Apache folder.

Uncomment lines below:

Include conf/extra/httpd-vhosts.conf
LoadModule vhost_alias_module modules/mod_vhost_alias.so

Save file and Restart your Apache and it will work. Many thanks to this guy: https://john-dugan.com/wamp-vhost-setup/

Check out this modules uncommented in httpd.conf

  • proxy_module
  • proxy_http_module

I am coming very late to this question, I did all what was mentioned by @RiggsFolly but one thing I changed made it to work instantly. I changed .dev to .test as .dev is reserved. hope this helps

try this on you apache httpd.config file:

    <VirtualHost *:80>
      ServerName mysite.dev
      DocumentRoot "g:\wamp\www\mysite\public"
     SetEnv APPLICATION_ENV "development"

     <Directory "g:\wamp\www\mysite\public">
        DirectoryIndex index.php
        Options All Includes Indexes
        Options All Indexes FollowSymLinks 
        Order allow,deny
        Allow from all
        Require all granted
     </Directory>
  </VirtualHost>

restart your wamp server and put url like mysite.dev/ on you browser. hope it will help you. thank you.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!