Debugging Cake PHP Applications

A common question new starters to CakePHP ask is regarding debugging. Many users start off with basic scaffolding and confronted with the uninformative error ....

Not Found

The requested URL /index.php was not found on this server.

This is because your CakePHP application is set to production mode. In production mode you would not want your visitors and clients seeing detailed error reports, it would worry them.

To find out what the actual problem is open up file app/config/core.php and find line 45(ish) and you will see the following ....


Configure::write('debug', 0);

Change the above value from 0 to either 1, 2 or 3 and you will get a much more helpful error message. We recommend you set it to 2.

Direct from the CakePHP comments itself; here is an explanation of each debug level...

* Development Mode:
* 1: Errors and warnings shown, model caches refreshed, flash messages halted.
* 2: As in 1, but also with full debug messages and SQL output.
* 3: As in 2, but also with full controller dump.

It is worth noting that when debug level is set to anything other than production mode (0), any 'flash' messages and redirects you have will not redirect automatically, you must click the link to forward on.


Useful Linux Commands

Frequent questions from clients hosted on our Linux servers regarding quick ways to acheive common task to manage their servers and the files on them have prompted this post.

Here are a list of useful server commands that can be used for those of you running Linux servers, and also will mostly work on Unix too. Root access maybe needed for some of these commands depending on your setup.

Change owner of files and directories
# chown -R user /dir/you/choose
-R
If a pathname on the command line is the name of a directory, chown changes all the files and subdirectories under that directory to belong to the specified owner (and group, if :group is specified). If chown cannot change some file or subdirectory under the directory, it continues to try to change the other files and subdirectories under the directory, but exits with a non-zero status.

Set permissions of all directorys, not files
find . -type d -exec chmod 777 {} \;

The above command changes permissions of all sub directories under the current directory... and doesn't effect files however. Make sure you cd to your directory first, doing this from / is a bad idea.

Check what processes are eating memory and CPU in Linux or Unix
top

The above command will list the most CPU-intensive processes running on your system in live time, as the processes change so does the information displayed. Newer linux installations also list memory useage on the same screen. You can delay the live updates if its all a bit fast by adding the -d flag.. for example, to delay screen updates by 10 seconds use:
top -d 10

More useful commands coming soon ... If you wish to request a command, please do so.


Magento Gets 40% Faster to Load

As boasted by Varien, Magento absolutely is a "platform for growth" however if like us you have been continually disappointed with the performance on a speed point of view from Magento 1.2 then there is good news. On March the 30th 2009 Magento announced the release of 1.3 and claimed that they have improved performance by 40% in both page loading time and memory usage. Keen to see this for our selfs, we loaded a fresh 1.3 installation with around 1,200 products yesterday and at first glance the catalog pages are much faster to load than in 1.2.

Additionally in 1.3 there is the option to use a 'flat' category type for databases of under 1,000 products which should improve performance again for smaller stores.

Magento 1.3 is still not lightening speed, though 1.3 is still quite a young release. Magento is certainly still a fantastic product and one to watch for the future.