Set apache directory permissions when using name virtual hosts
If you add virtual hosts to your apache conf be sure to set the directory permissions.
I created an alias in my windows etc/hosts file for different development directories:
127.0.0.1 localhosts dev1 dev2 dev3
Then I turned on NameVirtualHost:
NameVirtualHost *:80
First one recreates the default host:
<VirtualHost *:80>
ServerName localhost
DocumentRoot "c:/wamp/www/"
</VirtualHost>
Then add the virtual one:
<VirtualHost *:80>
ServerName gofrontrow1
DocumentRoot "C:\work\dev1"
</VirtualHost>
Woops, doesn’t work with a "You don’t have permission to access / on this server." The log shows
"client denied by server configuration".
Because… the directory permissions have only been set for the default host:
DocumentRoot "c:/wamp/www/"
<Directory />
Options FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Satisfy all
</Directory>
<Directory "c:/wamp/www/">
Options Indexes FollowSymLinks
AllowOverride all
# onlineoffline tag – don’t remove
Order Allow,Deny
Allow from all
</Directory>
To make dev1 work, I had to add this directive:
<Directory "C:\work\dev1">
Options Indexes FollowSymLinks
AllowOverride all
Order Allow,Deny
Allow from all
</Directory>
Note that you can embed this directly in the virtual server directive (this replaces the 2nd virtual server directive above:
<VirtualHost *:80>
ServerName gofrontrow1
DocumentRoot "C:\work\dev1"
<Directory "C:\work\dev1">
Options Indexes FollowSymLinks
AllowOverride all
Order Allow,Deny
Allow from all
</Directory>
</VirtualHost>