Clear directories during development

Overview of directory clearing

While you’re developing Magento components (modules, themes, and language packages), your rapidly changing environment requires you to periodically clear certain directories and caches. Otherwise, your code runs with exceptions and won’t function properly.

This topic provides guidelines on what directories to clear and when to clear them.

  • All directories discussed in this topic are default locations. It’s possible to customize these locations but doing so is beyond the scope of this topic.
  • This topic is not comprehensive. Please help us improve it by clicking Edit this page on GitHub at the top of this page. Watch this page for updates.

When you’re developing Magento components (modules, themes, and language packages), the following directories contain temporary or generated files you can clear periodically:

Directory Description
pub/static Contains js and html files for each store view.
var/cache All cacheable objects except the page cache. (This directory is empty if you use a third-party cache storage like Redis.)
var/composer_home Home directory for the Setup Wizard artifacts. Typically, you shouldn’t touch this directory; clear it only if you’re an experienced developer and are familiar with the Magento plug-in. For example, if the Component Manager or System Upgrade web-based utilities cannot find the correct components you can try clearing this directory; however, doing so adversely affects the performance of those utilities.
var/di Contains the compiled dependency injection configuration for all modules.
var/generation Contains generated code”.
var/page_cache Cached pages from the full page cache mechanism. (This directory is empty if you use a third-party HTTP accelerator like Varnish.)
var/view_preprocessed Minified templates and compiled LESS (meaning LESS, CSS, and HTML).

What directories to clear

The following table provides guidelines on what you should clear and when.

For this activity... you should clear these directories
  • Change a class if there is a plug-in related to it.
  • A change that results in generated factories or proxies (for example, a non-existent [factory]({:target="_blank"} declared in a class or a proxy declared in di.xml)
var/di, var/generation
Change any di.xml var/di, var/generation; also, run the code compiler again
Add, remove, enable, or disable modules var/di, var/generation, var/cache, var/page_cache
Add or edit a layout or theme var/view_preprocessed, var/cache, var/page_cache
Change LESS or templates var/view_preprocessed, var/cache, var/page_cache as well
Change `*.js` or `*.html` files pub/static
Add or edit a CMS page, cacheable block, or use the Magento Admin to change the configuration var/cache, var/page_cache

How to clear the directories

To only clear directories and not perform other actions, log in to the Magento server as the Magento file system owner and clear directories using a command like the following:

rm -rf <magento_root>/var/di/* <magento_root>/var/generation/*

You can also use the following command-line tools clear some directories for you. These commands perform other tasks as well; consult the linked documentation for more details.

Tool name Brief description What it clears
magento setup:upgrade Updates the Magento database schema and data. var/di, var/generation
magento setup:di:compile Generates code. var/generation (after which compiles code again)
magento deploy:mode:set {mode} Changes from developer mode to production mode and vice versa. var/di, var/generation, var/view_preprocessed
magento cache:clean [type] Cleans the cache. var/cache, var/page_cache