Using CakePHP Framework is one of my most favorite things to do. This is the first PHP framework I worked with, and until now, Iâ€™m still delighted by it. Now it is time for me to share my knowledge in CakePHP web development.
I think you are here because you already know what CakePHP is, but for those who has no idea yet, and donâ€™t want to read more on CakePHP.org, hereâ€™s a brief description: CakePHP makes building web applications simpler, faster and require less code.
I think there are really few blog posts out there with regards to beginner CakePHP tutorials. Most of them are also outdated. We will keep this CakePHP posts as updated as possible. So to the future reader of these posts, please drop something in the comment section below if you think there is something outdated!
We will start with the most basic thing to advanced. Hopefully I can finish this tutorial series in the shortest time possible.
2.0 Install CakePHP on Your Server
Below are few steps to make CakePHP alive in your hosting server, see sections 2.1 to 2.4 below.
By the way, if youâ€™re a super beginner and using a windows PC (localhost), you can follow this tutorial first to set up your localhost: 3 Steps to Install WAMP on Windows
2.1 Download CakePHP (Step 1)
Soâ€¦ what do you expect the first step will be? Of course, we will download the framework. Download the latest CakePHP version here: http://cakephp.org/
As of this writing, the version is CakePHP 2.3.6 stable.
Extract the ZIP file.
2.2 Put CakePHP on Your Hosting (Step 2)
I donâ€™t know, but I think most of you guys are using a localhost (your PC or something). Okay, so Iâ€™ll assume you are all using your localhost. If youâ€™re not, just give a comment so we can try help you with your issue.
After you download and extract the Framework files, you have to put it in your root directory. Iâ€™m using windows 8 and running with WAMP server, so in my case, my root directory is in:
Now after putting the extracted folder, my CakePHP directory is in:
Of course, we want to change the dirty name â€œcakephp-cakephp-b81c198â€³ to our â€œproject nameâ€.
So we have to rename it and for this tutorial, we will name it â€œCakePhpProjâ€, awesome name right? If you donâ€™t think so, you can choose the project name of your choice. Now we should have:
2.3 Run CakePHP
Too early to run? Youâ€™re correct. This is just a test run. We just want to confirm if CakePHP can respond at this stage.
So to run CakePHP: Go to your browser > type â€œlocalhost/CakePhpProjâ€œ
You might see something beautiful like this:
You might be disappointed or intimidated by now, but donâ€™t worry, Iâ€™m at your side! Proceed to the next step below.
2.4 Configure CakePHP
Alright, so weâ€™re going to address the issues on the previous screenshot, one at a time!
2.4.1 URL rewriting is not properly configured on your server.- Letâ€™s start with this problem, this error is rare if youâ€™re using a real hosting. But if youâ€™re using localhost, hereâ€™s the fix:
1. On you notification area (lower right corner), click the WAMP icon.
2. Hover your mouse to the â€œApacheâ€ folder
3. Hover your mouse to the â€œApache modulesâ€ folder
4. Find and click â€œrewrite_moduleâ€, WAMP will automatically restart and check that apache module.
After the fix, re-run our project on the browser, it should look like this now:
2.4.2 Please change the value of â€˜Security.saltâ€™ – To solve this, you have to to got the core.php file and just change the security salt string!
In my case, I have to open it in C:wampwwwCakePhpProjappConfigcore.php
Find the word â€œsaltâ€ (Ctrl+F on your editor, Iâ€™m using notepad++)
You should see the line of code that looks like:
Change the value to something like:
Then re-run the browser:
2.4.3 Please change the value of â€˜Security.cipherSeedâ€™ – The solution is the same with 2.4.2, just change the value and re-run!
2.4.4 Your database configuration file is NOT present. â€“ Now we have to make a database for our CakePHP application. If you need help doing that, hereâ€™s a guide: How To Create MySQL Database With PhpMyAdmin
After creating a database, we have to go again to the Config directory, in my case:
Now you should see a file named â€œdatabase.php.defaultâ€ and rename it to just â€œdatabase.phpâ€œ
After renaming it, we have to open it with our editor and supply the database details! In the $default array, what usually we have to change are the: database host, login (username), password and database
You would see something like this in default:
public $default = array( 'datasource' => 'Database/Mysql', 'persistent' => false, 'host' => 'localhost', 'login' => 'user', 'password' => 'password', 'database' => 'database_name', 'prefix' => '', //'encoding' => 'utf8', );
So weâ€™re going to change it to:
public $default = array( 'datasource' => 'Database/Mysql', 'persistent' => false, 'host' => 'localhost', 'login' => 'root', 'password' => '', 'database' => 'my_project_database', 'prefix' => '', //'encoding' => 'utf8', );
Now, re-run our project page in the browser, it should look like this:
Still having hard time? I can personally help you do this for only $5!
Thanks for reading this How To Use CakePHP Framework, A Getting Started Guide!