174

I've got a XAMPP installation running on Windows 7.

As soon as I add a VirtualHost to httpd-vhosts.conf, BOTH the 'regular' http://localhost AND the new dropbox.local aren't working.

This is what I added to my httpd-vhosts.conf:

<VirtualHost *:80>
    ServerAdmin postmaster@dummy-host.localhost
    DocumentRoot "E:/Documenten/Dropbox/Dropbox/dummy-htdocs"
    ServerName dropbox.local
    ServerAlias www.dropbox.local
    ErrorLog "logs/dropbox.local-error.log"
    CustomLog "logs/dropbox.local-access.log" combined
</VirtualHost>

So I looked up my dropbox.local-error.log for any information:

[Thu Feb 02 10:41:57 2012] [error] [client 127.0.0.1] client denied by server configuration: E:/Documenten/Dropbox/Dropbox/dummy-htdocs/

This error seems to be solved by adding

<directory "E:/Documenten/Dropbox/Dropbox/dummy-htdocs">
     Allow from all
</directory>

But now I get this error in dropbox.local-error.log:

[Thu Feb 02 10:45:56 2012] [error] [client ::1] Directory index forbidden by Options directive: E:/Documenten/Dropbox/Dropbox/dummy-htdocs/

Furthermore when I try to access http://localhost, I dont get any error in the regular error.log, although I get the error 403 when I try to access it.

Can anybody help... It's driving me mad :S

EDIT: Also in httpd.conf there is the following (I've seen it mentioned multiple times, so before anyone says it):

<IfModule dir_module>
    DirectoryIndex index.php index.pl index.cgi index.asp index.shtml index.html index.htm \
                   default.php default.pl default.cgi default.asp default.shtml default.html default.htm \
                   home.php home.pl home.cgi home.asp home.shtml home.html home.htm
</IfModule>
Leandro Bardelli
  • 10,561
  • 15
  • 79
  • 116
Highmastdon
  • 6,960
  • 7
  • 40
  • 68

9 Answers9

363

Okay: This is what I did now and it's solved:

My httpd-vhosts.conf looks like this now:

<VirtualHost dropbox.local:80>
    DocumentRoot "E:/Documenten/Dropbox/Dropbox/dummy-htdocs"
    ServerName dropbox.local
    ErrorLog "logs/dropbox.local-error.log"
    CustomLog "logs/dropbox.local-access.log" combined
    <Directory "E:/Documenten/Dropbox/Dropbox/dummy-htdocs">
        # AllowOverride All      # Deprecated
        # Order Allow,Deny       # Deprecated
        # Allow from all         # Deprecated

        # --New way of doing it
        Require all granted    
    </Directory>
</VirtualHost>

First, I saw that it's necessary to have set the <Directory xx:xx> options. So I put the <Directory > [..] </Directory>-part INSIDE the <VirtualHost > [..] </VirtualHost>. After that, I added AllowOverride AuthConfig Indexes to the <Directory> options.

Now http://localhost also points to the dropbox-virtualhost. So I added dropbox.local to <VirtualHost *:80> which makes it as <VirtualHost dropbox.local:80>

FINALLY it works :D!

I'm a happy man! :) :)

I hope someone else can use this information.

davejal
  • 6,009
  • 10
  • 39
  • 82
Highmastdon
  • 6,960
  • 7
  • 40
  • 68
  • 39
    FWIW, I did the same and still had problems acceding my vhost. However, adding `Require all granted` after `Allow from all` made my configuration work. – Camilo Díaz Repka Oct 06 '12 at 01:36
  • The `httpd-vhosts.conf` is a config file for Apache. Apache 'runs' the php-code. Download and install `xampp` and change the config as stated above. – Highmastdon Nov 12 '12 at 11:52
  • I also had to add 'Options FollowSymLinks' because my rewrite rules were not being allowed. – funwhilelost Oct 23 '13 at 17:47
  • 6
    As of Apache 2.4 the access control directives [order, allow, deny and satisfy are deprecated](http://httpd.apache.org/docs/2.4/upgrading.html#run-time]). Make sure you are running a lower version when using these directives, or use Require in stead. – Pascalculator Nov 21 '13 at 16:45
  • 4
    As @Pascalculator says, use `Require all granted` **instead**. I want to emphasize the **instead** because it wasn't working when I had the other options in my configuration, but when I only left this one behind it worked. – user2428118 May 08 '14 at 13:44
  • Can confirm all I needed to do was add the lines @CamiloDíazRepka suggested. I didn't need do anything else. – Gerico Jan 10 '15 at 15:53
  • Good man. All i needed was the ```Require all granted``` and all fixed for me. – Gerico Feb 05 '15 at 20:08
  • On my setup (xampp 3.2.1), having the "# << New way of doing it" at the end of the line was preventing Apache from starting correctly. After deleting that part of the line, everything worked fine! – JMac Feb 07 '15 at 12:14
  • @davejal too bad you remove the personal side of stackoverflow, this means we have to act like robots and cannot express human feelings anymore, even on Stackoverflow? (I know this is insinuating: and indirectly lifting on the success of this post, maybe?) – Highmastdon Jan 28 '16 at 13:30
  • Sorry, didn't mean to remove it to hurt you, so I put it back, I personally think there should be more EQ expressed here also, but I've been `brainwashed` – davejal Jan 28 '16 at 13:50
  • 1
    @davejal Thanks a lot and no problem :) I din't want to be a jerk about it. Indeed a little more EQ could be nice out here :) – Highmastdon Jan 29 '16 at 09:24
65

For me worked when I changed "directory" content into this:

<Directory  "*YourLocation*">
Options All
AllowOverride All
Require all granted  
</Directory>
Leandro Bardelli
  • 10,561
  • 15
  • 79
  • 116
Imix
  • 651
  • 5
  • 2
  • Apache 2.4.3 - now working with above addition, plus I had the Apache and MySQL services "checked" in the Control Panel which was causing XAMPP CP to stop responding. Unchecked services - Apache ran, but Access Forbidden error. Added the above permissions, and it works now. Thanks!! – Sean Kendle May 05 '14 at 17:16
  • 2
    Basically this - I was missing the Options directive. `Options Indexes FollowSymLinks` was all I needed on Apache2.2, YMMV – Ed Orsi May 10 '14 at 16:10
  • This worked wonderfully for me as opposed to the selected answer. For some reason "Require all granted" by itself as that answer suggests didn't work as it instantly crashed XAMPP. But this answer worked with those between so thanks for the answer. – Scrydan Mar 18 '15 at 09:42
  • Can someone please help me out here ? I am trying to achieve the same thing in MAMP http://stackoverflow.com/q/40405663/4480164 – code-8 Nov 03 '16 at 15:52
  • ONLY `Options All` worked for me! It is the missing ingredient! – Theodore R. Smith Mar 28 '17 at 09:37
  • Thanks! Was going bananas! – Riccardo Dec 16 '21 at 11:43
11

For me (also XAMPP on Windows 7), this is what worked:

<Directory "C:\projects\myfolder\htdocs">`
   AllowOverride All
   Require all granted
   Options Indexes FollowSymLinks
</Directory>` 

It is this line that would cause the 403:

Order allow,deny
lequebecois
  • 173
  • 2
  • 6
  • .htaccess was not working till I changed to your answer, thanks. – ssi-anik Jun 14 '15 at 17:44
  • when index.html is missing and you just want to show all pages on this folder, you may add only the following under directive: `Require all granted` and `Options Indexes FollowSymLinks` – tatskie Mar 22 '17 at 12:52
9

I'm using XAMPP 1.6.7 on Windows 7. This article worked for me.

I added the following lines in the file httpd-vhosts.conf at C:/xampp/apache/conf/extra.
I had also uncommented the line # NameVirtualHost *:80

<VirtualHost mysite.dev:80>
    DocumentRoot "C:/xampp/htdocs/mysite"
    ServerName mysite.dev
    ServerAlias mysite.dev
    <Directory "C:/xampp/htdocs/mysite">
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

After restarting the apache, it were still not working. Then I had to follow the step 9 mentioned in the article by editing the file C:/Windows/System32/drivers/etc/hosts.

# localhost name resolution is handled within DNS itself.
     127.0.0.1       localhost
     ::1             localhost
     127.0.0.1       mysite.dev  

Then I got working http://mysite.dev

Sithu
  • 4,752
  • 9
  • 64
  • 110
6

Thank you, that worked! But I replaced this

AllowOverride AuthConfig Indexes

with that

AllowOverride All

Otherwise, the .htaccess didn't work: I got problems with the RewriteEngine and the error message "RewriteEngine not allowed here".

Adam
  • 61
  • 1
  • 1
4

Above suggestions didn't worked for me. I got it running on my windows, using inspiration from http://butlerccwebdev.net/support/testingserver/vhosts-setup-win.html

For Http inside httpd-vhosts.conf

<Directory "D:/Projects">       
AllowOverride All
Require all granted
</Directory>

##Letzgrow
<VirtualHost *:80>
DocumentRoot "D:/Projects/letzgrow"
ServerName letz.dev
ServerAlias letz.dev    
</VirtualHost>

For using Https (Open SSL) inside httpd-ssl.conf

<Directory "D:/Projects">       
AllowOverride All
Require all granted
</Directory>

##Letzgrow
<VirtualHost *:443>
DocumentRoot "D:/Projects/letzgrow"
ServerName letz.dev
ServerAlias letz.dev    
</VirtualHost>

Hope it helps someone !!

Rahul Gupta
  • 75
  • 1
  • 10
3

After so many changes and tries and answers. For

SOs: Windows 7 / Windows 10

Xampp Version: Xampp or Xampp portable 7.1.18 / 7.3.7 (control panel v3.2.4)

Installers: win32-7.1.18-0-VC14-installer / xampp-windows-x64-7.3.7-0-VC15-installer

  1. Do not edit other files like httpd-xampp

  2. Stop Apache

  3. Open httpd-vhosts.conf located in **your_xampp_directory**\apache\conf\extra\ (your XAMPP directory might be by default: C:/xampp/htdocs)

  4. Remove hash before the following line (aprox. line 20): NameVirtualHost *:80 (this might be optional)

  5. Add the following virtual hosts at the end of the file, considering your directories paths:

    ##127.0.0.1
    <VirtualHost *:80>
        DocumentRoot "C:/xampp/htdocs"
        ServerName localhost
        ErrorLog "logs/localhost-error.log"
        CustomLog "logs/localhost-access.log" common
    </VirtualHost>
    
    ##127.0.0.2
    <VirtualHost *:80>
        DocumentRoot "F:/myapp/htdocs/"
        ServerName test1.localhost
        ServerAlias www.test1.localhost
        ErrorLog "logs/myapp-error.log"
        CustomLog "logs/myapp-access.log" common
        <Directory  "F:/myapp/htdocs/">
            #Options All # Deprecated
            #AllowOverride All # Deprecated
            Require all granted  
        </Directory>
    </VirtualHost>
    
  6. Edit (with admin access) your host file (located at Windows\System32\drivers\etc, but with the following tip, only one loopback ip for every domain:

    127.0.0.1 localhost
    127.0.0.2 test1.localhost
    127.0.0.2 www.test1.localhost
    

For every instance, repeat the second block, the first one is the main block only for "default" purposes.

Community
  • 1
  • 1
Leandro Bardelli
  • 10,561
  • 15
  • 79
  • 116
  • 1
    Setting different IP addresses for each virtual host worked! Unlike WAMP though, XAMP does not interpret each server name when they are all bundled up in one IP address (e.g. `127.0.0.1 localhost,test1.localhost`). – CPHPython Jul 19 '19 at 09:44
  • @CPHPython thanks for mention the differences and improve my answer. Glad to help! I remember fought a lot with this issue – Leandro Bardelli Jul 22 '19 at 13:35
  • 1
    thank you, glad to help as well! Before finding your answer, I had spent quite a while trying to figure out why the windows' hosts were not reflecting the servernames. – CPHPython Jul 22 '19 at 16:59
1

I am using xampp 1.7.3. Using inspiration from here: xampp 1.7.3 upgrade broken virtual hosts access forbidden

INSTEAD OF add <Directory> .. </Directory> in httpd-vhosts.conf, I add it in httpd.conf right after <Directory "D:/xampplite/cgi-bin"> .. </Directory>.

Here is what I add in httpd.conf:

<Directory "D:/CofeeShop">
    AllowOverride All
    Options  All
    Order allow,deny
    Allow from all
</Directory>

And here is what I add in httpd-vhosts.conf

<VirtualHost *:8001>
    ServerAdmin postmaster@dummy-host2.localhost
    DocumentRoot "D:/CofeeShop"
    ServerName localhost:8001
</VirtualHost>

I also add Listen 8001 in httpd.conf to complete my setting.

Hope it helps

Community
  • 1
  • 1
Tutompita
  • 639
  • 1
  • 5
  • 14
1

For many it's a permission issue, but for me it turns out the error was brought about by a mistake in the form I was trying to submit. To be specific i had accidentally put a "greater than" sign after the value of "action". So I would suggest you take a second look at your code.

Fred
  • 332
  • 4
  • 5