57

I am getting an 403 access forbidden when attempting to open a page under a vhost where the document root is sitting on a different drive than where apache is sitting. I installed using the apachefriends release. This is my httpd-vhosts.conf file:


NameVirtualHost 127.0.0.1

<VirtualHost 127.0.0.1> ServerName foo.localhost DocumentRoot "C:/xampp/htdocs/foo/public" </VirtualHost>

<VirtualHost 127.0.0.1> ServerName bar.localhost DocumentRoot "F:/bar/public" </VirtualHost>

When opening bar.localhost in my browser, Apache is giving me 403 Access Forbidden. I tried setting lots of different access rights, even full rights to everyone, but nothing I tried helped.

Edit: Thanks! For future reference, add 'Options indexes' within to show directory indexes.

RobbieGee
  • 1,581
  • 4
  • 15
  • 17

5 Answers5

64

You did not need

Options Indexes FollowSymLinks MultiViews Includes ExecCGI
AllowOverride All
Order Allow,Deny
Allow from all
Require all granted

the only thing what you need is...

Require all granted

...inside the directory section.

See Apache 2.4 upgrading side:

http://httpd.apache.org/docs/2.4/upgrading.html

Michael Klink
  • 664
  • 6
  • 2
50

Somewhere, you need to tell Apache that people are allowed to see contents of this directory.

<Directory "F:/bar/public">
    Order Allow,Deny
    Allow from All
    # Any other directory-specific stuff
</Directory>

More info

Mark Embling
  • 12,605
  • 8
  • 39
  • 53
  • 2
    For me, this file I had to modify was C:\Program Files (x86)\Apache Software Foundation\Apache2.2\conf\httpd.conf – Paul Ostrowski May 06 '12 at 21:57
  • @Moss - um, yes it does. If you're having difficulty then it is likely there is another problem - perhaps your configuration isn't being read or NTFS permissions are preventing Apache reading it. Perhaps its wise to post your own question if things still don't work for you...? – Mark Embling Jun 02 '12 at 17:28
  • Yeah, I did post my own question: http://stackoverflow.com/questions/10859271/wampserver-403-on-named-virtual-hosts-outside-of-www. I set permissions to Full Control for Authenticated Users, SYSTEM, Administrators, on every folder from the site up to the drive. What else can be done? – Moss Jun 03 '12 at 03:53
27

For Apache 2.4.2: I was getting 403: Forbidden continuously when I was trying to access WAMP on my Windows 7 desktop from my iPhone on WiFi. On one blog, I found the solution - add Require all granted after Allow all in the <Directory> section. So this is how my <Directory> section looks like inside <VirtualHost>

<Directory "C:/wamp/www">
    Options Indexes FollowSymLinks MultiViews Includes ExecCGI
    AllowOverride All
    Order Allow,Deny
    Allow from all
    Require all granted
</Directory>
cloudwhale
  • 524
  • 5
  • 4
  • 1
    (y) great! Add into vhosts.conf file – NaeN Sep 24 '15 at 09:29
  • Apache 2.4 + Windows 10 + XAMPP was giving me the same error (403 forbidden). Most of the answers give "Require all granted" & that was not working. Adding "Options Indexes FollowSymLinks MultiViews Includes ExecCG" worked ! Thanks ! – Deepak Thomas Sep 14 '19 at 09:11
0

I have fixed it with removing below code from

C:\wamp\bin\apache\apache2.4.9\conf\extra\httpd-vhosts.conf file

<VirtualHost *:80>
    ServerAdmin webmaster@dummy-host.example.com
    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 webmaster@dummy-host2.example.com
    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 added

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    DocumentRoot "c:/wamp/www"
    ServerName localhost
    ErrorLog "logs/localhost-error.log"
    CustomLog "logs/localhost-access.log" common
</VirtualHost>

And it has worked like charm

mujaffars
  • 1,395
  • 2
  • 15
  • 35
0

Solved 403: Forbidden when visiting localhost. Using ports 80,443,3308 (the later to handle conflict with MySQL Server installation) Windows 10, XAMPP 7.4.1, Apache 2.4.x My web files are in a separate folder.

httpd.conf - look for these lines and set it up where you have your files, mine is web folder.

DocumentRoot "C:/web"
<Directory "C:/web">

Changed these 2 lines.

<VirtualHost *:80>
 ServerAdmin webmaster@localhost.com
 DocumentRoot "C:/web/project1"
 ServerName project1.localhost
 <Directory "C:/web/project1">
  Order allow,deny
  allow from all
 </Directory>
</VirtualHost>

to this

<VirtualHost *:80>
 ServerAdmin webmaster@localhost.com
 DocumentRoot "C:/web/project1"
 ServerName project1.localhost
 <Directory "C:/web/project1">
  Require all granted
 </Directory>
</VirtualHost>

Add your details in your hosts file C:\Windows\System32\drivers\etc\hosts file

127.0.0.1 localhost
127.0.0.1 project1.localhost

Stop start XAMPP, and click Apache admin (or localhost) and the wonderful XAMPP dashboard now displays! And visit your project at project1.localhost

Dupls
  • 61
  • 3