WAMP virtual host not working

I am using Wamp 2.5. My Apache - 2.4.9 PHP: 5.5.12 MySQL: 5.6.17

I have the following configurations:

On my httpd.conf

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

On my G:\wamp\bin\apache\apache2.4.9\conf\extra\httpd-vhost.conf

 # 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 "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> <VirtualHost *:80> ServerAdmin webmaster@dummy-host.example.com DocumentRoot "g:/wamp/www" ServerName localhost ErrorLog "logs/localhost-error.log" CustomLog "logs/localhost-access.log" common </VirtualHost> <VirtualHost *:80> DocumentRoot "g:\wamp\www\mysite\public" ServerName mysite.dev </VirtualHost> 

On my c:\Windows\System32\Drivers\etc\hosts

 # localhost name resolution is handled within DNS itself. 127.0.0.1 localhost 127.0.0.1 mysite.dev # ::1 localhost 

I am trying to access my project using this URL: http://www.mysite.dev/ BUT I get Server not found error , I tried to access it using www.mysite.dev , http://mysite.dev , but still out of luck!

My virtual host has worked before, but I'm not sure why it is not working now. Some strange things are going on.

I'm not sure what is going on. Any ideas would be much appreciated!

Thanks!

+11
source share
7 answers

First you need to remove the dummy definition examples from your vhost-httpd.conf file. They are provided as examples only to get started with the syntax and should not remain in the active conf/extra/httpd-vhosts.conf , since they point to non-existent folders.

Therefore, 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> 

The second Apache 2.4.x supports IPV4 (127.0.0.1) and IPV6 (:: 1), so your hosts should look like this with the IPV4 and IPV6 version definitions for each site. The browser can use either of them arbitrarily, so you will need both options, but it will probably use the IPV6 network instead of IPV4 if both are actually active on your computer.

 127.0.0.1 localhost ::1 localhost 127.0.0.1 mysite.dev ::1 mysite.dev 

Now on the 2 virtual hosts that really exist on your system, try this as defining a virtual host:

 <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 of the <VirtualHost>....</VirtualHost> section tells Apache which IP addresses it is allowed to accept connections from, so using the Apache 2.4 Require local syntax restricts access, so only the PC running WAMPServer, that is, Apache, can connect to any of these sites.

Try not to mix Apache 2.2 syntax and Apache 2.4 syntax together in one definition. So do not 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 that you want other PCs on your local network to see your site, for example, a partner or children, etc., you can add this syntax to one or more definitions of your virtual host.

Allow only one other computer to your site

 Require local Require ip 192.168.1.100 

or 2 other computers

 Require local Require ip 192.168.1.100, 192.168.1.101 

Or someone on your LAN just use the first 3 of 4 quartiles of the IP address.

 Require ip 192.168.1 

Also avoid using 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 

This may solve your problems in the short term, but just waiting to catch you after a while, when you decide that you want to show your site to a friend / client / boss. If you reach the “Port Forwarding” stage of your router, so that the world will be included in your network, which will make ALL YOUR SITES available to the whole world.

It is better to change the definition of ONE virtual host for the ONE site that you want people to see for testing / boasting from Require local to Require all granted and allow access to this only site only from the Internet.

After making all these changes, be sure to restart Apache.

Also, if you modify the hosts file to activate chnages, you must either restart the computer or start them from the command line command line launched with the Runs as Administrator parameter.

 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 
+17
source

Due to Google acquiring .dev gTLD, creating .dev development sites is no longer possible, the best way to mitigate is to simply rename the development domain to .local or whatever 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) to inform .dev gTLD end users. Because the .dev domain in the hosts file is set to 127.0.0.1, it indicates that the connection is rejected.

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.

+5
source

The following works 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> 
+2
source

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

Uncomment the lines below:

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

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

+2
source

Check out these modules without commenting in httpd.conf

  • proxy_module
  • proxy_http_module
0
source

I come to this question very late, I did everything @RiggsFolly mentioned, but the one thing I changed made it work instantly. I changed .dev to .test since .dev is reserved. I hope this helps

0
source

try this on your 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> 

reboot your wamp server and put the url as mysite.dev/ in your browser. hope this helps you. thanks.

-1
source

Source: https://habr.com/ru/post/1203676/


All Articles