Default localhost can't be accessed after installing virtual hosts on WAMP

2.5k Views Asked by At

I'll really appreciate a little help with a problem I have been struggling with all day long... I installed WordPress locally using WAMP and everything worked fine. I created a folder inside C:/wamp/www an named it wordpress. I was able to access localhost only by typing localhost on the browser's URL and I accessed the site typing localhost/wordpress/ BUT when I decided to install another wordpress website I faced a problem. I created a second folder inside www, named it joanaweb and followed the steps of this tutorial: http://www.marolinedesign.com/tutorials/how-to-install-more-than-one-wordpress-site-on-your-local-wamp-server/ PLUS I removed the # before Include conf/extra/httpd-vhosts.conf located on httpd.conf which wasn't mentioned in the tutorial. After this the first website was accessed as before while the second by typing joanaweb....BUT i couldn't access localhost anymore :( I got just a 403 Error. In this website http://www.apptools.com/phptools/virtualhost.php at the end of the article I found a solution but it isn't working for me :/ They suggested using:

<VirtualHost 127.0.0.1>
DocumentRoot C:\Apache\htdocs
ServerName localhost
</VirtualHost>

Since I have htdocs located on another folder I used this code on httpd-vhosts.conf

<VirtualHost *:80>
DocumentRoot "C:/wamp/bin/apache/apache2.4.9/htdocs/"
ServerName localhost
ServerAlias localhost
ErrorLog "logs/localhost.log"
CustomLog "logs/localhost.log" common
</VirtualHost>

<VirtualHost *:80>
DocumentRoot "C:/wamp/www/joanaweb"
ServerName joanaweb
ServerAlias joanaweb
ErrorLog "logs/joanaweb.log"
CustomLog "logs/joanaweb.log" common
</VirtualHost>

What am I doing wrong??

Also this is all the code inside my hosts file(after the comments):

127.0.0.1       localhost
::1             localhost

127.0.0.1        localhost
127.0.0.1        localhost
127.0.0.1        localhost localhost
127.0.0.1        localhost wordpress
127.0.0.1        localhost joanaweb
127.0.0.1        localhost lifestylepro
127.0.0.1        localhost xxxxxTranslations

And this is the code inside httpd-vhosts.conf :

<VirtualHost *:80>
    ServerAdmin [email protected]
    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 [email protected]
    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>


<VirtualHost *:80>
    DocumentRoot "C:/wamp/www"
    ServerName localhost
    ServerAlias localhost
    <Directory  "C:/wamp/www">
        AllowOverride All
        <IfDefine APACHE24>
            Require local
        </IfDefine>
        <IfDefine !APACHE24>
            Order Deny,Allow
            Deny from all
            Allow from 127.0.0.1 localhost ::1
        </IfDefine>
    </Directory>
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot "C:/wamp/www/wordpress"
    ServerName wordpress
    ServerAlias wordpress
       <Directory  "C:/wamp/www/wordpress">
        AllowOverride All
        <IfDefine APACHE24>
            Require local
        </IfDefine>
        <IfDefine !APACHE24>
            Order Deny,Allow
            Deny from all
            Allow from 127.0.0.1 localhost ::1
        </IfDefine>
    </Directory>
    ErrorLog "logs/wordpress.log"
    CustomLog "logs/wordpress.log" common
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot "C:/wamp/www/joanaweb"
    ServerName joanaweb
    ServerAlias joanaweb
       <Directory  "C:/wamp/www/joanaweb">
        AllowOverride All
        <IfDefine APACHE24>
            Require local
        </IfDefine>
        <IfDefine !APACHE24>
            Order Deny,Allow
            Deny from all
            Allow from 127.0.0.1 localhost ::1
        </IfDefine>
    </Directory>
    ErrorLog "logs/joanaweb.log"
    CustomLog "logs/joanaweb.log" common
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot "C:/wamp/www/lifestylepro"
    ServerName lifestylepro
    ServerAlias lifestylepro
       <Directory  "C:/wamp/www/lifestylepro">
        AllowOverride All
        <IfDefine APACHE24>
             Require local
        </IfDefine>
        <IfDefine !APACHE24>
            Order Deny,Allow
            Deny from all
            Allow from 127.0.0.1 localhost ::1
        </IfDefine>
    </Directory>
    ErrorLog "logs/lifestylepro.log"
    CustomLog "logs/lifestylepro.log" common
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot "C:/wamp/www/xxxxxTranslations"
    ServerName xxxxxTranslations
    ServerAlias www.xxxxxTranslations
    <Directory  "C:/wamp/www/xxxxxTranslations">
        AllowOverride All
        <IfDefine APACHE24>
            Require local
        </IfDefine>
        <IfDefine !APACHE24>
            Order Deny,Allow
            Deny from all
            Allow from 127.0.0.1 localhost ::1
        </IfDefine>
    </Directory>
    ErrorLog "logs/xxxxxTranslations.log"
    CustomLog "logs/xxxxxTranslations.log" common
</VirtualHost>
1

There are 1 best solutions below

14
On

Ok first get rid of these 2 section of httpd-vhosts.conf, these 2 bits are just what Apache release as sample code to get you started and are irrelevant to WAMPServer as they point to locations that are not used by WAMPServer.

So delete these 2 definitions

<VirtualHost *:80>
    ServerAdmin [email protected]
    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 [email protected]
    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>

And then we come to your Virtual Hosts definitions, as you are using Apache v2.4.x I will remove the Apache versions checks and just use Apache 2.4 syntax to make it easier to understand.

# Should be the first VHOST definition so that it is the default virtual host
# Also access rights should remain restricted to the local PC and the local network
# So that any random ip address attack will recieve an error code and not gain access
<VirtualHost *:80>
    DocumentRoot "C:/wamp/www"
    ServerName localhost
    ServerAlias localhost
    <Directory  "C:/wamp/www">
        AllowOverride All
        Require local
    </Directory>
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot "C:/wamp/www/wordpress"
    ServerName wordpress
    ServerAlias wordpress
    <Directory  "C:/wamp/www/wordpress">
        AllowOverride All
        Require local
    </Directory>
    ErrorLog "logs/wordpress.log"
    CustomLog "logs/wordpress.log" common
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot "C:/wamp/www/joanaweb"
    ServerName joanaweb
    ServerAlias joanaweb
    <Directory  "C:/wamp/www/joanaweb">
        AllowOverride All
        Require local
    </Directory>
    ErrorLog "logs/joanaweb.log"
    CustomLog "logs/joanaweb.log" common
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot "C:/wamp/www/lifestylepro"
    ServerName lifestylepro
    ServerAlias lifestylepro
    <Directory  "C:/wamp/www/lifestylepro">
        AllowOverride All
        Require local
    </Directory>
    ErrorLog "logs/lifestylepro.log"
    CustomLog "logs/lifestylepro.log" common
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot "C:/wamp/www/xxxxxTranslations"
    ServerName xxxxxTranslations
    ServerAlias www.xxxxxTranslations
    <Directory  "C:/wamp/www/xxxxxTranslations">
        AllowOverride All
        Require local
    </Directory>
    ErrorLog "logs/xxxxxTranslations.log"
    CustomLog "logs/xxxxxTranslations.log" common
</VirtualHost>

Now there is the HOSTS file. This needs to include the ip address for both IPC4 i.e. 127.0.0.1 and the ip address for IPV6 i.e. ::1

So change your HOSTS file to this, removing the unnecessary duplication and adding IPV6 references :-

127.0.0.1  localhost
127.0.0.1  wordpress
127.0.0.1  joanaweb
127.0.0.1  lifestylepro
127.0.0.1  xxxxxTranslations

::1  localhost
::1  wordpress
::1  joanaweb
::1  lifestylepro
::1  xxxxxTranslations

Now to make sure these are loaded into the dnscache, launch a command window using the "Run as Administrator" option and run these 2 commands.

Alternatively, just reboot, to make these current.

net stop dnscache
net start dnscache

Now restart Apache, so these changes are picked up, and try your vhosts.