Search code examples
phpapachecakephpvirtualhostvirtual-hosts

VIrtualHost Options returns an index of the site folder


I am not sure why this is happening as I am not very knowledgeable when it comes to Apache. Below is a copy of my VirtualHost.

If this gives any extra help as to how to get it to work, I am trying to run a CakePHP site. I know the site itself has no issues as I have another location I manage the code from and can get it running locally through Apache there.

<virtualhost *:80>
    DocumentRoot "C:/sites/sitename"
    ServerName dev.sitename.com
    ErrorLog "logs/sitename.com-error.log"
    CustomLog "logs/sitename.com-access.log" common


    <directory "C:/sites/sitename">
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order Allow,Deny
        Allow from all
    </directory>
</virtualhost>

I am running this on Apache 2.0 and Win7sp1

UPDATE

I never found the real solution using the route I was on. I downloaded a fresh copy of WAMP and was soon able to get everything up and running, no problem.


Solution

  • In order to prevent apache from showing the directory listing, you need to disable indexes. Also, it's best to disable MultiViews as that will enable content-negotiating, which may produce unwanted side-effects

    Change the options to;

     Options -Indexes FollowSymLinks
    

    Then, check that the .htaccess file is present inside your webroot (C:/Sites/Sitename), as that file is used to enable mod_rewrite

    Additional pointers/hints

    First of all, make sure that the DocumentRoot is pointing to the right directory of your application;

    The standard directory structure of CakePHP looks like this;

    app
       /Config
       /Controllers
       /Views
       ......
       /webroot
    lib
       /Cale
    plugins
    

    The DocumentRoot should point to your `app/webroot' directory, which contains all 'public' files.

    Change the paths/directories in your virtual host to that directory and restart Apache.

    If you're still getting a 403 error, change the URL you're visiting in your browser to this;

    http://mywebsite.com/index.php
    

    If this does work, check if the .htaccess file is present in that directory and mod_rewrite is installed in your Apache.