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.
Top comments (0)