This post is a part of a series on Magento development for beginners. To read more, click here.
Before you start hacking away at code, you need to have your environment setup and ready for active development. This includes a number of server settings as well as some Magento settings in the admin panel.
With these settings, you can develop and debug in a smooth and obvious manner.
- Developer Mode
- Server Settings
- Cache Settings
- Log Settings
Instead of writing another article on how to install Magento, (which has been written to death by the way), I figured I would just point you to some of the best resources on installation.
For a simple, to-the-point tutorial, go to Siteground’s How to Install Magento Manually tutorial.
For an overly complex and convoluted tutorial aimed at devops, go to Magento’s tutorial.
By default, Magento does not throw errors on the screen. This can be a security risk. Instead, Magento logs errors to a log file and displays a generic error on the screen to the user. While this is good for production, we do not want this for development. Magento has a way for you to display errors on the screen, (and a host of other features). It is called “developer mode” and it is built right into the Magento code base.
To enable developer mode, all you have to do is set this in your Apache Virtualhost directive or your .htaccess file:
SetEnv MAGE_IS_DEVELOPER_MODE 1
If you set this in your .htaccess file, remember not to commit it to any sort of version control! Also, do not set this in production either!
By default, there are a number of PHP settings that are good for development, but bad for production. PHP disables these by default. Also, it is good to increase the memory limit and max execution time of your application, since you’ll be working with constantly changing code that is not cached.
To enable these settings, set them in your Apache Virtualhost directive or your .htaccess file:
php_flag display_errors 1
php_flag max_execution_time 1800
php_flag memory_limit 512M # or 1024M, etc.
Magento, in order to be more performant, caches a number of different elements. This helps save computing every time the page loads. These can be enabled, disabled, and flushed via the admin panel. We will want to disable these for active development.
To disable the cache, go to Admin -> System -> Cache Management.
From there, you can enable, disable, or flush any cache item you want. If your local environment, or development environment is lacking in hardware, you can simply disable the cache you are actively working on. For example, you can disable the config, layout, and block cache and leave the other caches on unless you are actively working on those particular sections of the application.
There are times when you might want to log messages or exceptions. By default, Magento disables logging. You can enable this feature in the System Configuration.
Go to Admin -> System -> Configuration -> Advanced -> Developer -> Log Settings.
From there, you can enable logging for system messages and exceptions.
You can find these log files under var/log.
To log messages and exceptions, you can use the following methods:
Here are some typical errors you receive when you are trying to set up these settings.
I cannot get an error or exception to print on the screen.
- Check to see if you can override settings in your .htaccess
- Check the spelling of your setting
- Check index.php to ensure no one else has overridden your setting.
PHP errors don’t display on the screen.
- Check to see if you can override PHP settings in your .htaccess
- Check the spelling of the PHP setting
- Check index.php to ensure no one else has overriden your setting.
Log files are not writing to the folder.
- Check to see if logging is enabled on website and store view scopes of the system configuration.
- Check to see if var/log has write permissions.
- Check your code. Does your code hit the Mage::log() ?
I hope this helps everyone get their environment ready for development!