Showing posts with label mf is learning PHP. Show all posts
Showing posts with label mf is learning PHP. Show all posts

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!

Saturday, January 01, 2011

PHP & Apache HTTP Server - Installation

I heard & known that the PHP was very popular technology for rapid web development. Maybe it's good just to get my brain fresh with some technology alternative, so I decided to start the learning.

OK, first mission is to make PHP works with Apache HTTP server. As usual, since these are open source projects, a lot of information out there, but very hard to find all in one place, and usually the version might be outdated when we are looking for it.

My environment is as follow:
1. Windows XP
2. Apache HTTP server v2.2: Downloaded the httpd-2.2.17-win32-x86-openssl-0.9.8o.msi from here Apache: 2.2
3. PHP Version 5.3.4: Downloaded the php-5.3.4-Win32-VC6-x86.msi from here PHP for Windows
- Please note the installer that will work for Apache is VC6

Install the Apache HTTP server before PHP, then we can take advantage of the PHP installer that it will auto-configure the necessary details to make the Apache web server to serve PHP.

There are my local installed 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>

To verify the PHP can be serve by Apache:
1. Go to <apache_web_server>/htdocs
- create a file name: phpinfo.php
- Put this line of code to the phpinfo.php file: <?php phpinfo(); ?>

2. Start the Apache web server

3. In browser, type this: http://localhost/phpinfo.php
- you should see a page as follow:
PHP loaded succesfully!


And this is the Apache httpd.conf for the section related to PHP. All lines are written by the PHP installer, exceptAddType application/x-httpd-php .php, I added it manually then it works:

------------------------------------------------------
#BEGIN PHP INSTALLER EDITS - REMOVE ONLY ON UNINSTALL
PHPIniDir "D:/Apps/PHP/"
LoadModule php5_module "D:/Apps/PHP/php5apache2_2.dll"
AddType application/x-httpd-php .php

#END PHP INSTALLER EDITS - REMOVE ONLY ON UNINSTALL
------------------------------------------------------

And here are some references I used to troubleshooting problem, good luck!
1. <php.directory>/install.txt
2. Setting up CakePHP with Apache

In fact, I think the 2nd reference is more useful for next blog.