Featured Image



Magento 2 Command List: Essential CLI Commands for Developers

Magento 2’s Command Line Interface (CLI) is a powerful tool for developers to manage installations, extensions, cache, and deployments. Below is a comprehensive guide to the most critical Magento 2 CLI commands, complete with explanations, use cases, and pro tips.

1. Setup Upgrade & Module Management

After installing a new module or extension, always run these commands to update the database schema and regenerate classes:

Key Commands

  • php bin/magento setup:upgrade
    • Updates the database schema.
    • Warning: Removes pub/static files. Use –keep-generated to preserve them:
      php bin/magento setup:upgrade --keep-generated
  • php bin/magento module:status
    • Lists all installed modules (enabled/disabled).
  • Enable/Disable Modules
    php bin/magento module:enable Namespace_Module
    php bin/magento module:disable Namespace_Module

When to Use

ScenarioCommand
New module installedsetup:upgrade
Debugging module issuesmodule:status
Disabling faulty modulesmodule:disable

2. Static Content Deployment

Deploy static files (CSS, JS, images) for frontend themes:

Core Commands

  • Basic Deployment
    php bin/magento setup:static-content:deploy
  • Language-Specific Deployment
    php bin/magento setup:static-content:deploy en_US
  • Theme-Specific Deployment
    php bin/magento setup:static-content:deploy --theme Magento/luma

Pro Tips

  1. Use –no-html-minify to skip HTML minification for debugging.
  2. Exclude themes with –exclude-theme.

3. Cache Management

Magento’s caching system speeds up performance but often requires clearing during development.

Cache Commands

CommandPurpose
php bin/magento cache:cleanCleans cached files
php bin/magento cache:flushFlushes all cache storage
php bin/magento cache:enableEnables all caches
php bin/magento cache:disableDisables all caches

When to Clear Cache?

  • After modifying XML layouts.
  • After updating configuration.
  • Before testing frontend changes.

4. Reindexing

Magento uses indexes for catalog, pricing, and search. Keep them updated!

Index Commands

  • Reindex All
    php bin/magento indexer:reindex
  • Check Index Status
    php bin/magento indexer:status

Index Modes

ModeDescription
Update on SaveReal-time (slows performance)
Update by ScheduleCron-based (recommended for production)

5. Deployment Modes

Magento 2 runs in three modes:

Mode Commands

  • Developer Mode (Debug-friendly)
    php bin/magento deploy:mode:set developer
  • Production Mode (Optimized)
    php bin/magento deploy:mode:set production

Comparison

FeatureDeveloper ModeProduction Mode
Static File GenerationOn-demandPre-generated
Error VerbosityDetailedMinimal

6. Advanced Commands

  • Dependency Injection Compilation
    php bin/magento setup:di:compile
  • Uninstall Modules
    php bin/magento module:uninstall Namespace_Module

7. Troubleshooting Tips

  1. Broken Frontend? Run:
    php bin/magento setup:static-content:deploy
    php bin/magento cache:flush
  2. Database Sync Issues? Reindex and upgrade:
    php bin/magento indexer:reindex
    php bin/magento setup:upgrade

Final Thoughts

Mastering Magento 2 CLI commands streamlines development and maintenance. Bookmark this guide for quick reference!

Further Reading:

Leave a Reply

Your email address will not be published. Required fields are marked *