Overview of actions to debug Magento

By default, Magento does not register messages about errors and exceptions; so if something bad or weird happens and you want to know what is going on. Here are some suggestions.

Turn on logging

To turn on the logging, you can navigate to System > Configuration > Developer > Advanced > Log Settings and set the «Enabled» option to «Yes»

You could also edit the index.php and add/uncomment this code
(uncomment only for testing purposes)

error_reporting(E_ALL);

Make sure you have full access permissions (777) to the /var/log folder. The logfiles are stored there

To analyse if your custom code is involved you can add your own message to the log file. In this case I used commecom.log, but you can use any filename.

Mage::log('your own text here', null, 'commecom.log', true);

Display errors in browser

You could also edit the index.php and add/uncomment this code
(uncomment only for testing purposes)

ini_set('display_errors', 1);

Edit your local.xml in the /var/errors folder and rename “local.xml.sample” to “local.xml” to start showing errors. There are options you can set in the file to either print or email the errors. The file provides the options within

if (isset($_SERVER['MAGE_IS_DEVELOPER_MODE'])) {
    Mage::setIsDeveloperMode(true);
    ini_set(’display_errors’, 1);
}

Also make sure to double check that you have:

Set developerMode

Mage::setIsDeveloperMode(true);

Display error code

Add following to code near your functions that (you think) cause the error.

Dump the content.

var_dump($variablename);

Display variables and array information.

print_r($variablename);

To display variables.

echo($variablename);

Turn on template hints

System > Configuration > Advanced > Developer > Switch to the store view you are looking at > Debug > set the «Profiler» option to «Yes»

If you don’t see the screen above but the screen below, make sure you choose a Store view

Remember to clear your cache.

You could also install the extension Easy Template Path Hints for turning on/off the template path hints for frontend and backend on the fly.

Clean and/or disable Cache

System > Cache Management  > Select All [check-boxes] > Actions = Disable > Submit.

I have been fooled by the cache multiple times. So don’t forget to either flush or disable your cache.

  1. Disable Cache: Disabling your cache makes sure you get the latest code processed. Because we use Redis cache we encountered that we need to Flush Cache to be 100% sure to see our latest code processed, especially xml. Do this via:
  2. Flush Magento Cache: Removes only those entries that Magento reliably tracks as it’s own. Sometimes the cache location “var/cache/” or cache service (like Memcache) is shared with other applications. “Flush Magento Cache” removes only those entries that Magento reliably tracks as it’s own.
  3. Flush Cache Storage:This clears everything in the cahce folder but might affect other applications that use that cache storage. Sometimes cache entries are not clearly tagged by Magento and Magento loses track of them. I primarily use the second button on a staging Magento. On live server I only use this option when I’m having difficulties tracking down the cause of a problem.

Show the names of the used controller, action, router or module

 echo $this->getRequest()->getControllerName();
 echo $this->getRequest()->getActionName();
 echo $this->getRequest()->getRouteName();
 echo $this->getRequest()->getModuleName();

Use these lines to echo the used controller, action, router or module, to give you more insights.

Disable Compilation

System > Tools > Compilation > Disable

By default compilation mode is disabled. So just check if the Compiler Status is Enabled or not.

Re-Index All

System > Index Management > Select All [check-boxes] > Actions = Reindex Data > Submit

Although this is not always a factor in finding the cause of an error. Especially after installing or updating extensions I will re-index. Sometimes new SQL code is not fully processed and re-indexation will eliminate or show this issue.

Show errors for specific IP address only

How to show code, template path hints, etc only your computer

In the same screen where you would enable template path hints, enter your IP address in the Developer Client Restrictions  field Allowed IPs. You can use www.whatismyip.com to see your own IP addres.

You can also add this code snippet to your php pages

<?php if (in_array($_SERVER['REMOTE_ADDR'], Array('00.000.000.000','00.000.000.000'))): ?>

code

<?php endif; ?>    

This helps finding issues on a live website without affecting the visitors.


So, what do you think ?