Installation
Installing CakePHP can be as simple as slapping it in your web server’s document root, or as complex and flexible as you wish. This section will cover the three main installation types for CakePHP: development, production, and advanced.
- Development: easy to get going, URLs for the application include the CakePHP installation directory name, and less secure.
- Production: Requires the ability to configure the web server’s document root, clean URLs, very secure.
- Advanced: With some configuration, allows you to place key CakePHP directories in different parts of the filesystem, possibly sharing a single CakePHP core library folder amongst many CakePHP applications.
Development
Just place your cake install inside your web server’s document root. For example, assuming your web server’s document root is /var/www/html, a development setup would look like this on the filesystem:
- /var/www/html
- /cake_1_2
- /app
- /cake
- /docs
- /index.php
- /vendors
- /cake_1_2
To see your CakePHP application, point your web browser to http://www.example.com/cake_1_2/
1 - list item bullets are confusing
These list item bullets are confusing... In the right sidebar, these are clickable... but here they are not. I think I would use a different icon and reserve these arrows for lists that have the jquery treeview functionality so that things stay consistent.
Production
In order to utilize a production setup, you will need to have the rights to change the document root for your web server. Choosing the production setup means the whole domain acts as a single CakePHP application.
The production setup uses the following layout:
- /path_to_cake_install/
- /app
- /webroot (this directory is set as the document root for the web server)
- /cake
- /docs
- /index.php
- /vendors
If this application was going to be hosted on Apache, the DocumentRoot directive for the domain would look something like:
DocumentRoot /path_to_cake_install/app/webroot
DocumentRoot /path_to_cake_install/app/webroot
To see your CakePHP application, point your web browser to http://www.example.com.
Advanced Installation
There may be some situations where you wish to place CakePHP's directories on different places on the filesystem. This may be due to a shared host restriction, or maybe you just want a few of your apps to share the same Cake libraries. This section describes how to spread your CakePHP directories across a filesystem.
First, realize that there are three main parts to a Cake application:
- The core CakePHP libraries, in /cake.
- Your application code, in /app.
- The application’s webroot, usually in /app/webroot.
Each of these directories can be located anywhere on your file system, with the exception of the webroot, which needs to be accessible by your web server. You can even move the webroot folder out of the app folder as long as you tell Cake where you've put it.
To configure your Cake installation, you'll need to make some changes to /app/webroot/index.php. There are three constants that you'll need to edit: ROOT, APP_DIR, and CAKE_CORE_INCLUDE_PATH.
- ROOT should be set to the path of the directory that contains your app folder.
- APP_DIR should be set to the path of your app folder.
- CAKE_CORE_INCLUDE_PATH should be set to the path of your CakePHP libraries folder.
Let’s run through an example so you can see what an advanced installation might look like in practice. Imagine that I wanted to set up CakePHP to work as follows:
- The CakePHP core libraries will be placed in /usr/lib/cake.
- My application’s webroot directory will be /var/www/mysite/.
- My application’s app directory will be stored in /home/me/mysite.
Given this type of setup, I would need to edit my webroot/index.php file (which will end up at /var/www/mysite/index.php, in this example) to look like the following:
// /app/webroot/index.php (partial, comments removed)
if (!defined('ROOT')) {
define('ROOT', DS.'home'.DS.'me');
}
if (!defined('APP_DIR')) {
define ('APP_DIR', 'mysite');
}
if (!defined('CAKE_CORE_INCLUDE_PATH')) {
define('CAKE_CORE_INCLUDE_PATH', DS.'usr'.DS.'lib'.DS.'cake');
}
// /app/webroot/index.php (partial, comments removed)if (!defined('ROOT')) {define('ROOT', DS.'home'.DS.'me');}if (!defined('APP_DIR')) {define ('APP_DIR', 'mysite');}if (!defined('CAKE_CORE_INCLUDE_PATH')) {define('CAKE_CORE_INCLUDE_PATH', DS.'usr'.DS.'lib'.DS.'cake');}
It is recommended to use the DS constant rather than slashes to delimit file paths. This prevents any missing file errors you might get as a result of using the wrong delimiter, and it makes your code more portable.
Additional Class Paths
It’s occasionally useful to be able to share MVC classes between applications on the same system. If you want the same controller in both applications, you can use CakePHP’s bootstrap.php to bring these additional classes into view.
In bootstrap.php, define some specially-named variables to make CakePHP aware of other places to look for MVC classes:
$viewPaths = array(); $controllerPaths = array(); $modelPaths = array(); $helperPaths = array(); $componentPaths = array(); $behaviorPaths = array();
$viewPaths = array();$controllerPaths = array();$modelPaths = array();$helperPaths = array();$componentPaths = array();$behaviorPaths = array();
Each of these special variables can be set to an array of absolute filesystem paths where extra classes can be found when requested. Make sure that each path specified includes a trailing slash.
Apache and mod_rewrite
While CakePHP is built to work with mod_rewrite out of the box–and usually does–we've noticed that a few users struggle with getting everything to play nicely on their systems. Here are a few things you might try to get it running correctly:
- Make sure that an .htaccess override is allowed. In your httpd.conf, you should have a section that defines your Directory on the server. Make sure the AllowOverride is set to All for the correct DocumentRoot.
- Make sure you are editing the system httpd.conf rather than a user- or site-specific httpd.conf.
- Is CakePHP missing its needed .htaccess files? This sometimes happens during copying or moving because some operating systems treat files that start with '.' as hidden. Make sure your copy of CakePHP is from the downloads section of the site or our SVN repository, and has been unpacked correctly.
- Make sure you are loading up mod_rewrite correctly. You should see something like LoadModule rewrite_module libexec/httpd/mod_rewrite.so and AddModule mod_rewrite.c in your httpd.conf.
- If you are installing CakePHP into a user directory (http://example.com/~username), you'll need to modify the .htaccess file in the base directory of your CakePHP installation. Just add the line "RewriteBase /~myusername/".
Fire It Up
Alright, let's see CakePHP in action. Depending on which setup you used, you should point your browser to http://example.com/ or http://example.com/cake_install/. At this point, you'll be presented with CakePHP's default home, and a message that tells you the status of your current database connection.
Congratulations! You are ready to create your first CakePHP application.

By xentek on 23/2/08
1 - Advanced Installation
In a typical shared hosting environment, you get a path like this for your vhosts:
/var/www/vhosts/site_name.com/
This is an ideal location for storing the core cake lib and other code that doesn't need to be in the webroot.
But the biggest limitation is that the host has your the document root for the vhost configured:
/var/www/vhosts/site_name.com/htdocs
Since other stuff on the system depends on a standard location for each site (especially control panel software like Plesk, CPanel, and the like), you can't really modify this.
What I'd like to see in this section is how you can adapt CakePHP to treat the htdocs folder as the web root, and be able to install all the other files outside of the webroot. The Advanced Install section starts to address this, but doesn't tell you where to put the index.php, and vendors folder.
Ideally, I see it looking something like this:
/var/www/vhosts/site_name.com/cakephp
Which has the app folder, the cake folder (which could optionally mapped elsewhere, if you wanted this to be a 'universal' library for the whole server), index.php (probably not needed), and docs.
The app/webroot folder would be mapped to /var/www/vhosts/site_name.com/htdocs
However it is unclear how one would actually do this in the current docs. Maybe the approach should be in telling the user how it finds each folder, and how you might actually go about telling it where to find the ones you want to use. But the biggest question that's left for me is, can you 'rename' the webroot folder... so that it can be called whatever your host forces you to call it?
I don't know... maybe its just as easy as uploading the contents of /cakephp to /var/www/vhosts/site_name.com and putting everything in app at /var/www/vhosts/site_name.com/htdocs and mapping it to this folder with the ROOT, and APP_DIR constants... But the docs don't really let me know if this would be possible.
By mardala on 23/3/08
2 - Here is what I did
Note, this is not tested beyond just an installation. ie, I haven't built a fully functioning site using cake so I haven't tested all possibilities of modifying the path tree. But ... with a few slight modifications I was able to setup cake so it existed under a new structure.
> should now point to where CAKE is located.
I defined > if you have ini_set it goes to null .. but I set it to: CAKE_CORE_INCLUDE_PATH.DS."mvc".DS
5. Modify this in paths.php:
APP --> I set it to MVC_APP.DS
Thats it. But note I haven't actually built anything yet, this is just a default installation. But I think its easy enough if you run into a path issue to fix it.
By mardala on 23/3/08
3 - Oops
Most of my example was deleted thru when it was posted. So I put it up here:
http://john.mardala.com/cake.txt
By kmedlinnc on 8/4/08
4 - Tutorial from my Blog
You are more than welcome to have the tutorial from my blog for this project. It covers rather more than just the installation, but you could easily take that piece out and post it here.
http://keithmedlin.com/?p=26
login to add a comment