DEV Community

Mahesh Prajapati
Mahesh Prajapati

Posted on

Magento 2 commands for maintenance and deployment

These commands are essential for maintaining Magento 2 and ensuring smooth operations in both development and production environments. They handle tasks like database migrations, optimizing code execution, preparing frontend assets, and clearing cache.

1. php bin/magento setup:upgrade

Purpose: Applies any new database schema updates, runs data patches, and sets up newly installed or upgraded modules.

When to use:

  • After installing/upgrading modules or themes.
  • After modifying database-related configurations.

2. php bin/magento setup:di:compile

Purpose: Compiles dependency injection (DI) configurations into generated code for faster execution and performance.

When to use:

  • After making changes to module code.
  • After enabling/disabling a module.
  • In production mode, before deploying.

3. php bin/magento setup:static-content:deploy –f

Purpose: Deploys static view files (CSS, JavaScript, images) into the pub/static directory.

When to use:

  • After making changes to frontend files (e.g., LESS, CSS, JS).
  • Before deploying your store in production mode.

4. php -dmemory_limit=6G bin/magento setup:static-content:deploy -f

Purpose: Same as above, but this version overrides PHP’s default memory limit to 6 GB during the deployment process.

When to use:

  • Use this when you encounter memory-related errors during static content deployment.

5. php bin/magento indexer:reindex

Purpose: Rebuilds Magento’s indexes to optimize database queries and improve store performance.

When to use:

  • After making changes to product, category, or other data in the database that affects storefront performance.

6. php bin/magento c:f

Purpose: This is shorthand for php bin/magento cache:flush, which clears all cached data from Magento.

When to use:

  • After making any configuration changes.
  • When cached data might cause unexpected behavior or prevent new changes from appearing.

Sentry blog image

Identify what makes your TTFB high so you can fix it

In the past few years in the web dev world, we’ve seen a significant push towards rendering our websites on the server. Doing so is better for SEO and performs better on low-powered devices, but one thing we had to sacrifice is TTFB.

Read more

Top comments (0)

Heroku

Build apps, not infrastructure.

Dealing with servers, hardware, and infrastructure can take up your valuable time. Discover the benefits of Heroku, the PaaS of choice for developers since 2007.

Visit Site

👋 Kindness is contagious

Immerse yourself in a wealth of knowledge with this piece, supported by the inclusive DEV Community—every developer, no matter where they are in their journey, is invited to contribute to our collective wisdom.

A simple “thank you” goes a long way—express your gratitude below in the comments!

Gathering insights enriches our journey on DEV and fortifies our community ties. Did you find this article valuable? Taking a moment to thank the author can have a significant impact.

Okay