noufalcep noufalcep - 1 month ago 15
PHP Question

Wamp directories not working after enabling virtual host

I have created a virtual host for a new application in wamp.

In my

httpd.conf


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


In my
httpd.vhosts.conf
I added a new host

<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot "C:/wamp/www/myapp"
ServerName myapp.local
ServerAlias 127.0.0.1
SetEnv APPLICATION_ENV "development"
<Directory "C:/wamp/www/myapp/">
Options Indexes FollowSymLinks MultiViews
AllowOverride all
</Directory>
</VirtualHost>


The virtual host is working fine. But the problem is my other apps that run without virtual hosts are not working.

When i open
http://localhost/fistapp/
it shows

Forbidden 403

You don't have permission to access / on this server.

Answer

Once you create a Virtual Host definition Apache basically ignores the localhost domain defined in the httpd.conf file, so you have to also define locahost in the httpd-vhosts.conf file as well. So your httpd-vhosts.conf file should look like this :

<VirtualHost *:80>
    ServerName localhost
    DocumentRoot c:/wamp/www
    <Directory  "c:/wamp/www/">
        Options +Indexes +FollowSymLinks +MultiViews
        AllowOverride All
        Require local
    </Directory>
</VirtualHost>

# made some amendments to this VH as well
<VirtualHost *:80>
  DocumentRoot "C:/wamp/www/myapp"
  ServerName myapp.local
  # not sure why this is here ServerAlias 127.0.0.1
  ServerAlias www.myapp.local

  SetEnv APPLICATION_ENV "development"

  <Directory "C:/wamp/www/myapp">
    Options +Indexes +FollowSymLinks +MultiViews
    AllowOverride all
    Require local
  </Directory>
</VirtualHost>

Dont forget to amend the C:\windows\system32\drivers\etc\hosts file to add your new domain like this

127.0.0.1  localhost
::1 localhost

127.0.0.1 myapp.local
::1 myapp.local
Comments