×
Login or create an account
If you have an account with us, please log in.

You have no items in your shopping cart.

Magento 2 File & Folder structure

Magento 2 File/ Folder structure is too complicated. We are not going to cover all files and folders within Magento 2, but the high-level ones only. 

¡How to tell the difference between a folder and directory? Actually, they are the same things. Though, when you refer to a command line interface like Linux it’s more correctly to use ‘directory’ instead of ‘folder’!

Magento 2 Folder structure

If you navigate to your Magento 2 root, you’ll see the next folders:

  • app;
  • bin;
  • dev;
  • lib;
  • pub;
  • var;
  • vendor.

Each folder consists of subfolders where the subfolders contain files. Let’s have a closer look at each of the folders:

/app

As well as in Magento 1, the folder contains the main Magento code; 

  • it includes the /app/design with subfolders;

adminhtml and frontend directories;
the /app/design/adminhtml and /app/design/frontend directories contain theme folders with various CSS and LESS files;

  • the /etc folder contains the di.xml configuration file;

the di.xml file contains class mapping and interface preferences;

  • the /app directory  may contain an /app/code subfolder (This depends on your install method. The code directory will be there in case you download the GitHub repository. Otherwise, all Magento 2 code will be contained in the vendor folder.);
  • if you have the /app/code subfolder within /app, it includes the Magento core code (One of the locations where you can develop your custom Magento code. The info is actual in case you don’t use composer to handle your custom code.).

/bin 

  • the directory contains the magento file or a CLI script;
  • the CLI script activates a console with a set of handy options: enable/disable cache; enable/disable modules; run an indexer, etc.

/dev

  • Magento 2 test scripts and a few tools for development are placed in the folder.

/lib

  • the directory contains several libraries packed separately from the Magento core;
  • the internal and web subfolders are also located here;
  • the internal directory contains server-side libraries and several font files;
  • the web subfolder contains client-side (JavaScript) libraries, jquery, modernizr, requirejs, prototype, scriptaculous. (The framework code will be included in the lib folder only in case you download the GitHub repository. Otherwise, Magento 2 code will be in the vendor folder.).

/pub

  • it should be set as your web root on the server you use (Apache, Nginx);
  • as you have noticed from the name the folder contains all the publicly accessible files;
  • index.php controller is also contained in the folder.

/var

  • caches and generated classes are all located in the folder;
  • the var folder includes cache, composer_home, generation, log, di, view_preprocessed, page_cache files.

/vendor

  • the folder is generated by composer using composer.json file;
  • the folder includes various packages that have been defined under composer.json.

Note that in Magento 2.2.x and later versions the folder var/generation was removed to the project root and renamed to generated. For more information see here.

Magento 1/ Magento 2 difference in Folder structure

The app, lib and var directories were included in Magento 1 too. Magento 2 contains such new directories as bin, dev, phpserver, pub, setup, update, and vendor. For those who have just migrated from the first version, here is a table with the basic purpose of the new directories:

directory purpose
app includes the design folder for themes; the configuration file env.php;
bin includes the Magento 2 command line tool named magento;
dev includes testing files for the Magento 2 Functional Testing Framework;
lib includes various libraries and packages ;
phpserver         includes router.php;
pub includes generated static files, the website media;
setup the performance toolkit and other important packages;
update similar to the downloader from Magento 1 and contains upgrade files;
var similar to Magento 1 and includes raw cache files,logs, and reports;
vendor the closest to app/etc/modules.

What is your deal? 

magento-1-2-folder-structure

  • now media, error, skin, js, get.php, cron.php, and index.php folders are placed to pub folder;
  • skin and js folders are put in pub/static folder. Static content can be maintained easier cia CDN now.;
  • js, css, images are divided into pub/static/adminhtml and pub/static/frontend (for backend and frontend correspondingly); 
  • if you are looking for migration tools and tests, as well as shell, have a dip into the dev folder;
  • setup directory is now used for installation process;
  • downloader, includes, pkginfo have been excluded from Magento 2.

¡Bear in view that Magento Enterprise and Magento Professional versions differ in folders!

Rate the answer?
Back to top