I'm new to Magento 2 and I'm trying to understand the purpose and appropriate usage of some important commands. Specifically, I would like to know more about the following commands:

bin/magento setup:upgrade bin/magento setup:di:compile bin/magento static:content:deploy -f What are the specific functionalities and benefits of these commands in a Magento 2 project? When should each of these commands be used, and what tasks do they perform behind the scenes? Are there any best practices or considerations to keep in mind when running these commands?

I would greatly appreciate any insights or explanations that can shed light on the proper usage and advantages of these Magento 2 commands.

2 Answers 2


bin/magento setup:upgrade:

Purpose: This command is used to apply database schema and data changes for installed modules. When to use: It should be executed after installing or upgrading modules, or when there are changes to the module's database schema or data. It ensures that the database structure is up to date with the codebase.

bin/magento setup:di:compile:

Purpose: This command compiles Magento's dependency injection (DI) configuration and generates the DI configuration files. When to use: It should be run after installing or upgrading modules, or when there are changes to the DI configuration files (di.xml). It ensures that the DI configuration is up to date and speeds up the dependency injection process.

bin/magento static:content:deploy -f:

Purpose: This command deploys static view files such as CSS, JavaScript, and images for storefront themes and modules. When to use: It should be used when deploying the Magento application to a production or staging environment, or when changes have been made to static files. The -f option is used to force redeployment and overwrite existing files.

  • 1
    you are welcome
    – Madhan V
    Commented Jun 24, 2023 at 18:09
  • 1
    When there is any change in the constructor then we should run the s:up?
    – Rana Zain
    Commented Jun 27, 2023 at 7:07

bin/magento static:content:deploy -f should never be used in developer mode unless you are in a very specific debugging case. I em phase on the -f parameter.

By default in developer mode on page load Magento creates automatically symlinks in pub/static/. There is no need to copy files with this command. There are cases for example when you rename a JS file and than you have to empty with a system command (rm) the contents of pub/static/.../theme folder. When you copy a file in the theme with -f parameter and you change a file in app/design/frontend/... than the change won't be propagated automatically in pub/static/ because you no longer use symlinks. If you have the need to use bin/magento static:content:deploy -f it means that Magento isn't installed properly (file permissions, user and groups, etc).

bin/magento static:content:deploy is used primarily in production mode as described by Madhan V. Magento team designed the-f parameter for edge cases.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.