Sunday, January 02, 2011

CakePHP - installation

After PHP & Apache HTTP Server installation is done, I continue the setup with CakePHP.

So, my environment is:
1. Windows XP
2. Apache 2.2
3. PHP Version 5.3.4
4. CakePHP 1.3.6: Downloaded from here CakePHP 1.3.6.zip

And here is my directory structures:
1. Apache: D:/Apps/Apache2.2, I will refer this as <apache_web_server>
2. PHP: D:/Apps/PHP, I will refer this as <php.directory>
3. CakePHP: D:/Apps/cakephp_1_3_6, I will refer this as <cakephp.directory>

Configuration changes in Apache httpd.conf
Step 1) Make sure this line is there, and un-commented:
------------------------------------------------------
LoadModule rewrite_module modules/mod_rewrite.so
------------------------------------------------------

Step 2) Update the document root to the <cakephp.directory>. For e.g. in my case, it will be as follow:
------------------------------------------------------
DocumentRoot "D:/Apps/cakephp_1_3_6"
------------------------------------------------------

Step 3) Make sure the option to overwrite is enabled
------------------------------------------------------
<Directory />
Options FollowSymLinks
AllowOverride All
# Order deny,allow
# Deny from all
</Directory>
------------------------------------------------------

(Re)Start the Apache web server, try to access the application by: http://localhost/index.php, you should see a page as follow:
PHP loaded succesfully!


I faced some errors during setup, here are some that I can remember:
Problem 1) The index page doesn't load, there are warning message something as follow
------------------------------------------------------
strtotime() [http://php.net/function.strtotime]: It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone
...
------------------------------------------------------
Solution 1) add this line to the <cakephp.directory>/app/config/core.php: ------------------------------------------------------
date_default_timezone_set('Asia/Kuala_Lumpur');
------------------------------------------------------
-> This problem seems like happen to PHP 5 onwards ??
Of course you can add different timezone, checks this out list of supported timezone

Problem 2) Index page does not contains any css, logo and etc.
Solution 2) Update the DocumentRootin the Apache httpd.conf, point it to the <cakephp.directory>, so, in my case, it will be as follow:
------------------------------------------------------
DocumentRoot "D:/Apps/Apache2.2/htdocs/cakephp_1_3_6"
------------------------------------------------------
Please note this: !! CAKEROOT should NOT be sub-directory of the Apache htdocs !!

Yeah, it is strange for me that I finally found out I have to move the CakePHP application out from the Apache default document root, which is the htdocs. But as I reference from this website, the colorful page only shown up in my local after I move it out.

So, my main reference to setup CakePHP are:
1. The CakePHP cookbook
2. Troubleshooting

I think next will be CakePHP with MySQL, hopefully I managed this by next week :)

Good luck!

No comments: