Magento 2.1.18 is the final 2.1.x release. After June 2019, Magento 2.1.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)
  • 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 command as follows (there are no options):

1
bin/magento setup:di:compile

The following message displays to confirm success:

1
Generated code and dependency injection configuration successfully.

Optional. Compile code before installing the Magento application

In some cases, you might want to compile code before you install the Magento application. To do that, you must first enable modules; otherwise, the compiler has nothing to do. To compile code for only some modules, enable only those modules.

The following command enables all modules:

1
bin/magento module:enable --all [-c|--clear-static-content]

Use the optional [-c|--clear-static-content] option to clear static content. This is necessary if you’ve previously enabled or disabled modules and you must clear static content previously generated for them.

More information about enabling modules.

Compile code

Use this command to compile code.

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

1
bin/magento setup:di:compile

The following message displays to confirm success:

1
Generated code and dependency injection configuration successfully.
Updated