Avai Avai - 3 months ago 13
Apache Configuration Question

WAMP virtual host displays in Chrome, but Internet Explorer says "Page can't be displayed"

I installed WAMP and followed this guide to set up virtual hosts. In both Google Chrome and Internet Explorer, http://localhost gets me to "WAMPSERVER homepage" with my virtual host listed under "Your Projects."

Clicking that link to http://mysite.local in Chome brings me to my site as expected.

Clicking that link in Internet Explorer displays the following message instead.


This page can’t be displayed

•Make sure the web address http://mysite.local is correct.

•Look for the page with your search engine.

•Refresh the page in a few minutes.


Since I can see the WAMPSERVER homepage as expected in both browsers, I don't think there's a problem with my WAMP installation. Since my virtual host is working in Chrome, I think it must be configured properly in Apache and in my Windows hosts file.

I just don't understand why Internet Explorer isn't working with my virtual host like I expect it to, and the "Page can't be displayed" message doesn't give me anything helpful to work with.

Does anyone have any suggestions for me? I'd greatly appreciate any pointers or links to other guides I can try. Thanks in advance for any replies!

Answer

There's several reasons WAMP/MAMP may not work on a local environment, I'll try to list a few reasons here:

Which httpd.conf?

There are sometimes multiple httpd.conf files that can cause things to go a little bit funny. MAMP/WAMP usually tend to keep all their configuration files within a conf/ directory however, that doesn't mean to say some other httpd.conf file is being used...

You can also run this command on Linux based systems to see which one is being used:

apache2ctl -V | grep SERVER_CONFIG_FILE

vhosts definitions not included in httpd.conf

In the httpd.conf file, there's a line to include the vhosts definitions file, it should be uncommented:

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

Incorrect vhosts definitions

Vhosts need to be defined as follows:

<VirtualHost *>
    DocumentRoot "C:/path/to/your/local/site"
    ServerName mydomain.local
</VirtualHost>

Hosts file

On OS X/Linux systems this can be found at etc/hosts. Edit that to reflect below (note, you'll need to be root)

127.0.0.1    mysite.local

On windows systems, it can be found in %SystemRoot%\System32\drivers\etc\hosts.

Browser caches

Browser caches always cause an issue with local servers/development. It's worth working with incognito mode on, or deleting all browser caches each and every time you open it up. There's a few plugins available for most browsers that should help too.

Other points to note

  • Whenever you edit anything to do with httpd.conf, vhosts, hosts file - WAMP/MAMP/Apache needs to be restarted. It's a good idea to shut the server down before doing the changes.
  • You mentioned that there was a hardcoded link in one/some of your files. It's generally regarded as bad practise to do that for this exact reason. Your code is less portable and can 'break' on other systems. I'd suggest using PHP's __FILE__ or similar to achieve what you want.
    • Alternatively you could set up local configuration files for your app that are only included when they're present. Have a look at this for a good example of such a set up.
  • Log everything. Check the logs regularly too.
Comments