CakePHP is an open-source framework for PHP intended to make developing, deploying and maintaining applications much easier. CakePHP offers many useful design patterns, such as the Model-View-Controller pattern, seen in other popular frameworks like Ruby On Rails. The CakePHP framework also provides a slew of valuable reusable libraries for dealing with common tasks. An example is "Inflector" (a routine that takes a string and handles pluralization).
This guide will attempt to point you in the right direction so you can get started with CakePHP and eventually develop your own applications using it.
Step 1: Why CakePHP?
A significant amount of development time with PHP is spent rewriting common code for routine operations such as database access or returning data to the browser. Of course, all this routine code can quickly become disorganized in traditional PHP applications. What is needed is a framework for PHP that does what Ruby On Rails did for Ruby.
CakePHP has been around for awhile and does exactly that. It provides a number of useful libraries in support of common tasks and includes facilities for organizing code in folders and associating code with files. As a result, time spent writing and organizing code becomes greatly reduced.
Below are just a few things CakePHP offers to make development easier.
Step 2: Download The Framework
Before you start developing with CakePHP you will need your own copy of the framework uploaded to your server. Visit CakePHP.org and click the large "Download" button. Make sure to download the stable release and not the release candidate. There are also many different file formats available so you can pick the best one for your computer.

Step 3: Uploading and Understanding the File Structure
Once you have your fresh copy of CakePHP out of the oven, the next step is to upload the copy to a PHP and MySQL enabled web space. I would recommend creating a new directory for CakePHP projects.
Once the upload has finished the directory structure should look something like this:
/path_to_root_folder
/cake/
/docs/
/app/
config/
controllers/
models/
plugins/
tmp/
vendors/
views/
webroot/
index.php
.htaccess
/vendors/
index.php
.htaccess
All these directories or folders may look a little daunting at first, but the separate directories are meant to better organize all of the framework components. Since names like "tmp" aren't self-explanatory here is what these folders are for:
- The cake folder stores all the core functions and internals for CakePHP. You will usually not need to edit anything here.
- The docs folder contains very little, but does hold the license information (COPYING.txt), a change log and some other useful files. This directory is not important for CakePHP to run so you can remove it if you wish.
- The app folder is where your application code will go. The app folder will hold your controllers, configuration, templates and much more.
- The config folder contains all the configuration files for the application. This includes database details, access list, inflections and routes (URL rewriting).
- The models folder stores all the sql database functionality for your application.
- The views folder stores all the templates, layouts (header, footer) and helper modules that assist functionality (such as AJAX).
- The controllers folder stores all the controllers for your application. A controller is the part of the application that directs and controls the model and the views by accepting input and deciding what to do with it.
- The plugins folder stores plugins which are a combination of models, views and controllers that can be packaged and used in other applications. Examples are user management modules or an RSS module.
- The tmp folder stores cache files generated by the caching system and also stores debugging logs. This folder will be very valuable during development.
- The vendors folder, can contain other libraries that you want to include in a particular application.
- The webroot folder stores static media such as CSS, images and the JavaScript needed by your application.
- The second vendors directory will allow you to store third-party libraries and hook into them from your CakePHP controllers. For example if we wanted to built a Facebook application with CakePHP we could drop in the Facebook library and configure CakePHP to load it.

Step 4: Configuring CakePHP
Configuring CakePHP is pretty straightforward. We just need to tell CakePHP our database details and set up how we want the core functionality to work.
For development purposes you should create a new database and a user with the following privileges: ALTER, CREATE TEMPORARY TABLES, CREATE, DELETE, DROP, SELECT, INSERT, UPDATE, REFERENCES, INDEX, LOCK TABLES.
Once the user and database have been created, we can find CakePHP's database configuration file, located in /app/config/database.php.default
Open and scroll down to the following array
var $default = array('driver' => 'mysql',
'connect' => 'mysql_connect',
'host' => 'localhost',
'login' => 'user',
'password' => 'password',
'database' => 'project_name',
'prefix' => '');
and fill in your database details as necessary. If for some reason you cannot create a new database, or your host does not allow it, you can set a table prefix for all your CakePHP tables by setting a value in the 'prefix' index. Make sure to rename this file to /app/config/database.php
More core configuration is located in /app/config/core.php. You can change the level of debugging information, how sessions are stored, session time outs for security, and the names of cookies. Once we start developing we may need to adjust these, but the defaults are fine for most needs.
Step 5: Making Sure it Works
Once you have entered the correct database details and uploaded all the CakePHP files, the installation should be ready for development. Point your browser to the folder that you uploaded the installation to. If everything is working, you should see the following success page:

Closing
This tutorial was meant to introduce the basics of CakePHP and how to get it up and running on your server. In future installments we will look at developing an application from the ground up using CakePHP, adding effects such as AJAX, and integrating CakePHP with other libraries and services such as Facebook.
- Subscribe to the NETTUTS RSS Feed for more daily web development tuts and articles.
Related Posts
Check out some more great tutorials and articles that you might like
Plus Members
Source Files, Bonus Tutorials and
More for $9 a month for all TUTS+
sites in one subscription.












User Comments
( ADD YOURS )Kai October 17th
Im new to PHP framework and stuff and I was looking for this!
Thank you very much!
( )Bryan P. October 17th
I have done some searching of my own, looking at different frameworks for PHP. I have noticed some seem to get my “media” attention. Out of curiosity why did you choose to cover CakePHP instead of another framework?
( )Justin October 17th
Looking forward to the rest of the series!
( )John October 17th
Great stuff; as well as following the Create Your Own PHP Framework tutorials (Where’s the next one???) this will be a great series to follow. Keep up the good work NetTuts!
( )Ben Griffiths October 17th
This should be a great series - CakePHP is brilliant to use, but it can be very daunting to those new to frameworks
( )chris simpson October 17th
CakePHP is a great ruby-on-rails esque framework, great to have a series on here where people can learn it.
Great work!
( )insic October 17th
hmmm another series. and now its cake. nice.
( )Connor October 17th
Good Job Justin! This looks like a good series.
( )Salman October 17th
Great stuff
thanks for the tut
( )Barttos October 17th
Nice post, but frameworks is not so good for professional developing!
( )Ben Griffiths October 17th
Barttos - what do you mean? - frameworks are fantastic for professional development!
( )Dan October 17th
Cool, I tried this once and failed. I think I’ll give it another go.
( )Sean October 17th
CodeIgniter > CakePHP
CI has miles better documentation.
( )Jeremy October 17th
I had to use cakephp for a project and at first it kinda drove me nuts because it seemed to make things harder, but once you actually learn how to use it, I LOVE MVC now and try to do any project that I can in it. Everyone needs to give it a chance
( )Kevin Quillen October 17th
This is one of the better code frameworks out there. I wish we were using more of it. Nice.
( )Gafroninja October 17th
I haven’t tried CakePHP, because I’m still in love with Code Igniter.
( )Chris October 17th
Great intro, looking forward to the next article!
Barttos, I have to agree with Ben - most frameworks are great for professional development. Cake (and others) are used by lots of web pros.
( )Sabandija October 17th
Well I think it’s nice to have many tutorials going on here at NETTUTS but I’d prefer to have less and be able to focus on them instead, thanks anyway for the goods tuts you have here guys.
( )Furley October 17th
YAY! I have been asking for this since this site started. Can’t wait for future installments.
( )Josh October 17th
I’m fairly new to PHP in general and have had no experience with frameworks. I’ve been following along with the create your own PHP frameworks and have enjoyed this tutorial. Would creating your own framework be better than using an established framework such as CakePHP?
( )Furley October 17th
@Josh - Cakephp is a more developed framework with a great community of support and documentation, than a custom framework. You just wont get that with your own custom framework, but being new to php you may want to play around with your own framework to familiarize yourself with the language. You may ultimately decide that no framework best suits you or your project, but you will learn alot. I think it depends on your project.
( )Ben Mills October 17th
I was just thinking about how it would be nice to see some Cake on NETTUTS this morning, and when I got to work and checked there was this article!
Great work Justin!
( )insic October 17th
I agree with Sean. I love CI
( )insic October 17th
@Barttos I hope you don’t mean with your comment about frameworks. Else you are wrong.
( )Janckos October 17th
Desearia ver por aca tutoriales de CakePHP.
( )Buen post, felicitaciones.
Barttos October 17th
Ben, Chris, insic, this is only my opinion! I use frameworks (ZF) only when dead-line is near me
( )Kevin Quillen October 17th
Frameworks are a must to keep your projects organized and clean. They allow for rapid development of web applications and are a godsend in a group production environment.
( )David Rojas October 17th
About time!
( )Thanks, Justin. I’ve been waiting for a cakephp tutorial here for a long time.
Abdullah Al-Ageel October 17th
Seems a god series to follow .. count me as a follower.
( )Patrick October 17th
hm… i’ve tested some frameworks out, but i don’t use them, they’re mostly (much) slower than my own code. And, the really bad thing of a framework like CI or Cake - you don’t learn really much about PHP and how it works. That’s in my opinion a really, really bad thing… they are helpfull, when a deadline is too short to you, but it’s not a better way to code.
( )Lamin Barrow October 17th
Man.. CakePHP is good. I am keenly looking forward to the rest of the tuts.
( )sloser October 17th
@Barttos frameworks are ONLY solution for professional developing, IMHO
If you use it on your every project, dead-lines will be not be threat any more
( )Stefan October 17th
Waw, you got the exact next thing on my to-learn list: “A PHP framework, probably Cake”!
( )Armando Sosa October 17th
Hey! Great tutorial, I’m already an old time Cake Lover (I did the site) and my advice will be: Download the 1.2 release candidate. Altough it’s a .2 release, the differences between 1.1 and 1.2 are HUGE. 1.1 is good, but once you use 1.2 you’ll have no doubt that CakePHP is the best framework out there.
I know that 1.2 stable is about to be released, but the RC is stable enough. Anyway, you are still learning don’t you?
I’m looking forward to this series.
(Btw, as you can see, English is not my first language. Sorry for that)
( )Daniel Hofstetter October 17th
Like Armando I recommend to use CakePHP 1.2, even though it is still a RC.
( )Jash Sayani October 18th
Wow! This is just what I was looking for! Thanks a lot !
( )Abhinav Singh October 18th
Excellent stuff
For those interested in Symfony, here is an excellent tutorial:
( )http://abhinavsingh.com/blog/2008/10/getting-started-with-symfony-a-php-framework-part-1/
Juan October 18th
Hey man, you should try 1.2, i think telling people to not download it is a bit misleading, 1.2 is stable enough for almost every project, also 1.1 is almost dead, and all the developing and documentation efforts are now spend in 1.2.
And they are very different, a lot of things have change to a better way. also 1.2 is not new stuff, it has been on developing like for a year (as far as i have tracked the project) but it seems to me, that the core team want to make it perfect to release it as a proper stable.
(English is not my first language)
( )Christian Dalsvaag October 18th
Barttos: Using a framework like CakePHP, CodeIgniter and (Rails if you’re on Ruby) is GREAT for professional development. This actually is what professional development is today. None of the big companies write code from scratch. People rely mostly on WordPress and even Joomla! for CMS. This is just a better way of rapid development.
Patrick: Are you serious? Well, when you are a professional developer I bet you don’t need to learn from writing code. I’m not saying we’re not learning, we’re always learning new things. But of course you are learning! Do you really know what a PHP framework is? When you use it, you TYPE PHP. Object Oriented Programming > Non-OOP. I can agree that it might be slower, but development is more rapid!
( )Barttos October 18th
@Christian, “None of the big companies write code from scratch.”… - really? Every big companies have her own framework for anykind of projects.
( )Christian Dalsvaag October 18th
Barttos: Well, now - of course they make their own frameworks too. But I was talking about writing code from scratch for every project. Anyway, as I were saying - most companies rely on already-finished frameworks; and when I say that I’m not talking about all countries, but at least in Norway.
( )Ivan October 18th
I was expecting so much more from the first Cake tutorial. Shame.
( )pixelsoul October 18th
Lets try not to get a framework and something like Wordpress confused. Wordpress is not a framework.
I think that if you are new to PHP you should get your hands dirty at first and learn the basics but in the same breath you can learn a little OOP if you work with Cake. I think frameworks though are great for rapid development in a professional environment, especially when you have more then one developer working on the the project and I do know that a lot of companies use them and/or build their own for consistency if not for anything else.
( )Shane October 18th
Using frameworks is a bit of a no-brainer - use what you’re familiar with, and what works for you
( )John Rico October 19th
Frameworks are just a way to abstract some ideas but they will keep you on one and only one way to do the things.
I think is better the Zend Framework approach as modules decoupled or components and you could still follow the MVC pattern or another way. I’m agree with some posters that frameworks are not always the best answer. If you follow good practices, patterns and your PHP code its OOP, there will be no problems even without a framework and you could get better performance without layers and layers of abstraction that frameworks impose to you.
Frameworks are good for RAD but not so much of Flexibility.
2c.
( )alex October 19th
Looking forward to getting my teeth into this
( )Garrett St. John October 20th
Just getting my feet wet with web development using CakePHP. I’m really looking forward to reading the upcoming tuts!
( )Jonny October 20th
I’m still skeptical. I’ll download it and try it out, but as a long-time PHP/MySQL user, i always find myself going back to coding things the ‘old-fashioned’ long way. I’m not anti-change… I’ve found Jquery to be an Excellent tool for me, and now use it extensively, but when it comes to server side scripting, I always find myself needing the flexibility that doing it my own way offers.
( )Kevin Quillen October 20th
Have you done a lot of large scale projects with multiple people involved?
( )Designer October 21st
neat…. always good to learn something more
( )Jatin V Meshiya October 21st
Very important issues covered in this initial starter kit. we are looking forward eagerly to have the next part. Please.
( )mmhan October 21st
I was secretly wishing that you guys would cover cakePhp. Looking forward to more cakephp posts.
( )Martin Bavio October 21st
I´ve been using CakePHP for a year, and it didnt disapointed me in any aspect. Highly recomended, specially version 1.2, that has a HUGE list of cool features.
( )Suresh PHP October 24th
Frameworks are good for RAD but not so much of Flexibility. Better to have our own framework
( )notingsudo October 25th
@sureshphp : your own framework VS community-driven framework ?
you can tell me now.
@john rico : “Frameworks are good for RAD but not so much of Flexibility.”
you my friend directly underestimated the knowledge of core developers
and the community.
Framework is good. Try them. then you are a believer.
( )chris simpson October 31st
guys wheres the second installation of this?
( )Pavel November 21st
Can u help me please? Where can I find out that my database is connected as you mentioned in point 5. I have it already uploaded. thanks
( )Pavel November 21st
It’s ok. I have it!!!
( )kareem November 23rd
this is wonderful tutorial i will put acopy of this lesson on
( )my site here
http://www.as7ap4you.com
Temur January 5th
I did not see the success page. It shows me a page with bunch of info about CakePHP like getting started and I see a notice line saying that “Notice (1024): Please change the value of ‘Security.salt’ in app/config/core.php to a salt value specific to your application [CORE\cake\libs\debugger.php, line 556]“
( )Eduardo Costa Garcia January 26th
I get de same message any one know how i proceed to resolve this?
( )Hanafi February 7th
Edit your /app/config/core.php
( )Go to line 151 and change the default salt
> Configure::write(’Security.salt’, ‘DYhG93b0qyJfIxfs2guVoUubWwvniR2G0FgaC9mi’);
to something else. Like ‘PYhG93b0qyJfIxfs2guVoUubWwvniR2G0FgaC9m’ for example
Abrar February 15th
It has brilliant unique style than others. Great.
( )amjad February 16th
I love to work with cake. you are only one
( )Riddhi February 27th
After doing as specified above: “Cake is NOT able to connect to the database.” error is coming..Please help.
( )