Magento 2.0.18 is the final 2.0.x release. After March 2018, Magento 2.0.x will no longer receive security patches, quality fixes, or documentation updates.
To maintain your site's performance, security, and PCI compliance, upgrade to the latest version of Magento.

Code compiler

In addition to the command arguments described in this topic, see Common arguments.

Run all Magento CLI commands as the Magento file system owner.

Overview of code compilation

This section discusses the basics of code compilation. Code compilation consists of all of the following (in no particular order):

  • Application code generation (factories, proxies, and so on)
  • Area configuration aggregation (that is, optimized dependency injection configurations per area)
  • Interceptor generation (that is, optimized code generation of interceptors)</li>
  • Interception cache generation
  • Repositories code generation (that is, generated code for APIs)
  • Service data attributes generation (that is, generated extension classes for data objects)

You can find code compilation in classes in the \Magento\Setup\Module\Di\App\Task\Operation namespace .

Run the single-tenant compiler

Run the command as follows (there are no options):

bin/magento setup:di:compile

The following message displays to confirm success:

Generated code and dependency injection configuration successfully.

In Magento versions 2.0.5 and earlier, there is a known issue with the single-tenant compiler; it does not currently compile proxies. Therefore, if you’re preparing to deploy to production, you must use the multi-tenant compiler.

The issue was resolved in Magento versions 2.0.6 and later.

Run the multi-tenant compiler

Use this command if you have multiple tenants, which means more than one independent Magento application. In other words:

  • There is one Magento 2 code base instance
  • There is one database instance per tenant
  • Independent configurations in the Magento Admin per tenant
  • The storefronts are independent of each other

If you do not have multiple tenants, use the single-tenant compiler instead.

Command options:

bin/magento setup:di:compile-multi-tenant [--serializer="{serialize|igbinary}"] [--extra-classes-file="<path>"] [--generation="<path and
filename>"] [--di="<path and filename>"] [--exclude-pattern="<regex>"]

The following table discusses the meanings of this command’s parameters and values.

Parameter Value Required?


Specify either serialize or igbinary. Default is serialize.



Specify the absolute file system path to proxies and factories that are not declared in the dependency injection or code..



Absolute file system path to a directory for generated classes. Default is <your Magento install dir>/var/generation



Absolute file system path to a directory to generate the object manager configuration. Default is <your Magento install dir>/var/di



Regular expression that enables you to exclude paths from compilation. Default is #[\\/]m1[\\/]#i)


For example, to run the compiler and specify the igbinary serializer:

bin/magento setup:di:compile-multi-tenant --serializer=igbinary

Messages similar to the following display:

Generated classes:
    ... more messages ...
    On \*nix systems, verify the Magento application has permissions to modify files created by the compiler in the "var" directory.
    For instance, if you run the Magento application using Apache, the owner of the files in the "var" directory should be the Apache user
    (example command: "chown -R www-data:www-data <MAGENTO_ROOT>/var" where MAGENTO_ROOT is the Magento root directory).