Initial Magento Setup Development Tips
Initial Magento Setup Development Tips

Initial Magento Setup Development Tips

Published December 30, 2009 in Development
Shortening Increment ID length for Orders, Invoices, and Shipments
October 4, 2009
Enable/disable template/block Hints Using MySQL
January 8, 2010

Over the past year and a half of developing Magento sites, our development team has created a standard set of modifications/tweaks that we make to every Magento installation.


1. Automatically turn on developer mode based on the domain.

We have a stage site setup for all of our projects at We also develop projects locally at either .dev or .local (based on developer preference). This snippet of code will only enable error reporting and Magento’s developer mode on stage or local domains.

Insert the following code after “require_once $mageFilename;” in index.php

2. Enable logging

Magento has a built-in logging method that allows you to log any variable type to a log file. This is very helpful when building Magento modules, as you can easily inspect data structures, without having to open a debugging session to inspect the variables in local scope. By default, logging is turned off in Magento. To enable logging, go to the “Developer” tab on the “System > Configuration” page. Change the “Enabled” select list under the “Log Settings” section to “Yes” and then save the page.

You can log variables to the Magento log using the following code: Mage::log($variable); By default, logs are stored in var/log/system.log

Here are some example usages of Mage::log()

If you’re developing on a Mac, I’d recommend opening the system.log file with the Console app. If you’re on a *nix based machine, you “tail” the latest contents of the log file using the following bash command:
tail -f


3. Enhance error backtraces

All of our developers use xdebug as a part of their Apache configuration. Xdebug has two main benefits: (1) It allows us to use PDT to debug PHP applications. (2) It overrides the default PHP error messages with detailed, fully customizable error backtraces. You can see an example backtrace below:

Xdebug Error Backtrace

This is what that error would look like without xdebug:

Generic Magento Error

Magento has built-in error and exception handling. Since errors are being handled by Magento, we have to modify a core file to make Magento let PHP/xdebug handle the displaying of the messages.

In a future blog post, will cover how to make Magento let xdebug handle exceptions

In app/code/core/Mage/Core/Model/App.php, replace the setErrorHandler() method with the setErrorHandler() method below:

Modifying core Magento files is never recommended, but if Magento gets upgraded and this change gets overridden, there won’t be an issue, since it’s not critical for the site to function.

4. Enhance exception backtraces

In this Enabling Xdebug’s Exception Handler in Magento blog post, you can read about how to modify Magento to let Xdebug handle exceptions.


Hopefully, these few tips will help you in your Magento development.  If you have any general tips for Magento development, I’d love to hear about them.


  1. Mike says:

    Thanks a lot, saves lots of time.

    • bluescrubbie says:

      Thanks for the great contribution!
      in your first snippet (the index.php addition), do you mean ‘.local’ for your second array element? You’ve got ‘ocal’ now.

    • ehansen says:

      @bluescrubbie – Thanks. Yes, I do mean ‘ocal’, as that code only checks the last four characters of the base url. I could have used code like this, but I didn’t see the need for the overhead of the extra function calls:

    • James says:

      When you want the best eCommerce platforms plus the best design of your business site, the Los Angeles Magento Developer is a group who can cater what you need. There is now about 110,000 clients trusting them.

    • Ken says:

      Thanks! I would love to see the tutorial on using xdebug (including setup) which was mentioned. These tips have come in handy with my herbal store.

      And to bluescrubbie — I believe “ocal” was used instead of “local” in order to handle capitalization.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.