Codegento Who Let Mage Out Of The Cage?

28Mar/1126

Debugging Magento Step by Step

Although these debugging tips can be applied towards any LAMP application (for the most part), we wanted to give a more narrowly focused step by step debugging checklist for Magento.

Get XDebug or ZendDebugger Working
I, personally, don't know how anyone can develop effectively outside of an IDE (mine being Eclipse PDT), or without a debugging environment. When all else fails, putting a breakpoint in the beginning of your backtrace and stepping line by line is the best way to debug and/or learn what Magento is doing.
Articles about setting up XDebug with PDT
Articles about setting up ZendDebugger with PDT

Clear the Cache
If you are using caching at all within Magento, one of the first steps to answering the question - "Why is this not working?" - is to clear the Magento cache. There are two ways to clear the cache:
System > Cache Management > Select All > "Refresh" Massaction > Submit
Delete the "cache" directory under BASE_MAGENTO_DIR/var

Clear the Browser Cache
More than once, I have wasted 10 minutes trying to figure out why something wasn't rendering to the browser correctly, only to find that my browser was caching old responses. If you don't know how to clear your browser cache, see the following links:
Firefox
Internet Explorer
Safari
Google Chrome

Make Sure Your Configurations Are Set For the Proper Scope
Because the System > Configurations can be set for specific scopes (Default / Website / Store View), we have to make sure that we have set the configurations for the proper scope. To check this, use the Magento Admin Panel -
System > Configuration > Upper Left Corner (Change to the scope/store view you are working with)

Turn On Logging
This one is a big one. Almost EVERY time, if there is a problem in Magento, something will appear in either the system.log or the exception.log. Checking these logs should become second nature to you. To turn on logging, use the Magento Admin Panel -
System > Configuration > Advanced > Developer > Log Settings > Enable
Check the magento exception.log under BASE_MAGENTO_DIR/var
Check the magento system.log under BASE_MAGENTO_DIR/var

Use Template Path Hints
Template Hints are pretty amazing. When you want to figure out which Block or phtml file a problem is occurring in, you can turn on template hints and see the information right on the browser. It's awesome, so if you haven't tried it, try it right now.
To turn on template path hints, use the Magento Admin Panel -
First, you NEED to select the store view you want to show the hints on. If you don't, the configuration option won't appear.
System > Configuration > Advanced > Developer > Debug > Template Path Hints and/or Add Block Names to Hints
By default, there is no way to turn on hints for the Admin Panel, so take a look at this article for help: Enable Template/Block Hints in Admin Panel

Tracing
If you have implemented a home-grown tracing mechanism, turn it on and look at the log. A common tracing mechanism consists of coding tracing statements within the code that log ENTRY into a function, important information within the function, and EXIT from the function. This information can be crucial in debugging problems in a production environment.

XDebug Tracing
XDebug provides some pretty kick-butt tracing ability. If you turn it on, get ready for a lot of data, but it can be very helpful when trying to pinpoint a problem. In the article "Tracing PHP Applications with xdebug" it gives some really good information about xdebug tracing.

Check the Apache error_log
When all else fails, take a look at the apache error_log. It could be a problem with the setup of your webserver.

Google It
It may come as a surprise, but there are still people that don't turn to Google as a "troubleshooting option". They should. When you want to ask a developer something, first ask it to Google. For instance, if you want to know how to do a rewrite of a model, just Google: How do I rewrite a model in Magento. If you want to know why you are getting an error like "HEADERS ALREADY SENT", Google: headers already sent magento. Chances are, another developer will give you a response like THIS if you ask them the question anyway.

Search Or Ask The Magento Forums
One of the big pros to Magento is the active community members. Many are willing to help answer your questions for free, and quickly. Before you ask your question, search the forums. If you don't find your answer, ask your question.

Ask Your Questions in IRC Chat
(irc.freenode.net) #magento
The guys in here are cranky but some of them know there stuff, so ask your question, wish upon a star, and hope they answer.

Use the Varien_Profiler
If you are having performance issues, turn on and use the Varien_Profiler. Do this in the Admin Panel -
System > Configuration > Advanced > Developer > Debug > Profiler
http://inchoo.net/ecommerce/magento/keeping-your-magento-fit-with-built-in-profiler/
http://activecodeline.net/extending-default-magento-profiler
http://www.neptuneweb.com/blog/?id=24

Then, if you still can't figure it out, start all over again. :)

Posted by Ben Robie

Comments (26) Trackbacks (0)
  1. Hi Ben

    Thanks for sharing the info.
    Besides:
    If you want an easy way without going to the backend everytime for turning on/off the template path hints, you can use the following community extension called Easy Template Path Hints:
    http://www.magepsycho.com/easy-template-path-hints.html

    Morever it works for both frontend and backend by passing query string as like in joomla.

    Happy E-Commerce!!

  2. For development purposes I recommend using Magneto-Debug: https://github.com/madalinoprea/magneto-debug

    Is really cool and not because I’ve did it ;) http://www.youtube.com/watch?v=aqvgrmebcu4 (the video is outdated, few other features were added)

  3. Why use an exstension for those pathhints or clearing cache or anything?

    http://www.classyllama.com/magento/introducing-wiz-a-cli-tool-magento

    Check this on for size

    • Toon, we use Wiz regularly as well. That is a good addition to this list. I was introduced to it much after this post was published.

  4. Many thanks for the tips, the Template Path Hints can be a big timesaver.

  5. Howdy, i read your blog from time to time and i own a
    similar one and i was just curious if you get a lot of spam comments?
    If so how do you protect against it, any plugin or anything you
    can advise? I get so much lately it’s driving
    me insane so any support is very much appreciated.

  6. That is a good tip particularly to those new to the
    blogosphere. Brief but very precise info… Many thanks for sharing
    this one. A must read post!

  7. Hi, everything is going perfectly here and ofcourse
    every one is sharing data, that’s truly good, keep up writing.

  8. Heya are using WordPress for your site platform?
    I’m new to the blog world but I’m trying to get
    started and set up my own. Do you require any html coding
    knowledge to make your own blog? Any help would be greatly appreciated!

  9. Greetings! Very helpful advice within this
    article! It’s the little changes that make the greatest changes.

    Many thanks for sharing!

  10. Hello, I think your site might be having browser compatibility issues.
    When I look at your blog in Firefox, it looks fine but
    when opening in Internet Explorer, it has some overlapping.

    I just wanted to give you a quick heads up! Other then that, wonderful
    blog!

  11. I visited multiplе web paǥes but the audio featjre for aսdio songs present at this website is genuinely wonderful.

  12. Hello are using WordPress for your site platform?
    I’m new to the blog world but I’m trying to get started and set up
    my own. Do you need any html coding expertise to make your own blog?

    Any help would be greatly appreciated!

  13. I know this website gives quality based articles or reviews and extra material, is there any
    other web site which gives these kinds of information in quality?

  14. Simply buy these smart touchscreen gloves and use your phone without any
    trouble. This gives net users the chance to examine the facts with a considerable amount of time.
    You can browse from hundreds of different songs in MP3 files that can be
    turns into ringtones. Smartphones also have larger screens
    and are great for games and video and have the capabilities of a
    mini computer. It is a common reason why people buy
    accessories for phone as they are not meant to be durable and
    they are bound to get damaged or worn out.

  15. ңi there, I check yοur new stuff regularly. Your story-telling style is witty, keep doung what you’rе ɗoing!

  16. It’s an remarkable post in support of all the online viewers; they will
    take advantage from it I am sure.

  17. Excellent pieces. Keep writing such kind of information on your site.
    Im really impressed by it.
    Hello there, You’ve performed an excellent job.
    I’ll definitely digg it and individually suggest to my friends.
    I am sure they will be benefited from this web site.

  18. Hi, all is going sound here and ofcourse every one is sharing information, that’s genuinely excellent, keep up writing.

  19. New customers and potential prospects shall be amazed with how responsive you’re.

  20. Although she could possibly not have arrived at acclaim as a
    consequence of her Lyric Poems, the try was undoubtedly a welcome 1, since a lot of people feel that
    these participants and actresses from Walt disney are several talentless little ones baiting on the acceptance.
    Nowadays audio is certainly one inside the most beneficial instruments
    for inducing relaxing. His canaries are called edge canaries, the
    vocal kind, all yellow colored.

  21. whoah this weblog is great i like studying your posts. Stay up the good work!
    You realize, lots of individuals are searching around for this info,
    you could help them greatly.

  22. I know this web site presents quality based posts and extra information, is there any other web site which
    provides these information in quality?

  23. you are in reality a good webmaster. The site loading pace is amazing.
    It seems that you are doing any distinctive trick. Also, The contents are masterwork.
    you’ve performed a magnificent process on this topic!

  24. I have been exploring for a bit for any higth qualty articles or weblog posts in this kind of house .
    Exploring in Yahoo I finally stumbled upon this web site.

    Reading this info So i’m satisfied to express that I’vea very good
    uncanny feeling I discovered exactly what I needed.
    I so much surely will make sure to don?t omit this site annd provides it a look
    regularly.


Leave a comment

(required)

Trackbacks are disabled.