3. Setting Up CakePHP

The first way to setup CakePHP is generally only recommended for development environments because it is not secure. The second way is considered more secure and should be used in a production environment.

3.1. Development Setup

For development we can place the whole Cake installation directory inside the specified DocumentRoot like this:

/wwwroot/
    /cake
        /.htaccess
        /app/
        /cake/
        /index.php
        /tmp/
        /vendors

In this setup the wwwroot folder acts a the web root so your URLs will look something like this:

www.example.com/cake/index.php

If you are using mod_rewrite, your URLs will follow the http://www.example.com/cake/controller_name/action_name/param1/param2 pattern.

3.2. Production Setup

In order to utilize a production setup, you will need to have the rights to change the DocumentRoot on your server. Doing so, makes the whole domain act as a single CakePHP application.

The production setup uses the following layout:

../path_to_cake_install/
    /.htaccess
    /app/
        /config/
        /conftrollers
        /index.php
        /models
        /plugins
        /views
        /webroot <-- This should be your new DocumentRoot
    /cake/
    /index.php
    /tmp/
    /vendors

Example 3.1. Suggested Production httpd.conf

DocumentRoot /path_to_cake/app/webroot

In this setup the webroot directory is acting as the web root so your URLs might look like this:

http://www.example.com/

If you are using mod_rewrite, your URLs will follow the http://www.example.com/controller_name/action_name/param1/param2 pattern.

Some users on shared hosts without access to their httpd.conf directives may not be able to change their DocumentRoot to reflect the production setup. Users in that situation may want to try and structure their Cake installation as follows. The Cake installation is found at /path_to_cake_install, and the DocumentRoot (which cannot be changed) points to/public_html.

/path_to_cake_install
    /app
    /cake
    /index.php
    /models
    /plugins
    /views
    /webroot

/public_html (= contents of /app/webroot)
    /.htaccess
    /css    
    /css.php         
    /favicon.ico     
    /files           
    /img             
    /index.php       
    /js

Essentially, you copy the contents of Cake's /app/webroot folder into your existing DocumentRoot. In order to tell Cake where the webroot files are, add the following lines to the index.php file in your DocumentRoot folder (/public_html/index.php in the example above.)

define('ROOT', BASE_DIR.'/path_to_cake_install');
define ('APP_DIR', 'app');
define ('WEBROOT_DIR', '/public_html');