1.06

Magento CLI Commands

Understanding bin/magento commands in the development cycle.

Why This Matters: The CLI is a trusted, powerful tool for interacting with Magento during development. Knowing essential commands and their usage is critical for efficient development.

CLI Command Categories

mindmap root((bin/magento)) Setup setup:install setup:upgrade setup:di:compile setup:static-content:deploy Module Management module:status module:enable module:disable Cache cache:flush cache:clean cache:enable cache:disable Indexing indexer:reindex indexer:status indexer:set-mode Development dev:source-theme:deploy deploy:mode:set Admin admin:user:create

CLI Basics

Why Use the CLI?

bin/magento provides an easy way to interact with Magento during development.

Key Benefits:
  • Trusted Environment - CLI access requires server access
  • Automation - Commands can be scripted
  • Efficiency - Faster than GUI operations
  • Development Essential - Many operations only available via CLI

Command Abbreviation

You can shorten commands to any unique combination of characters:

Full Command Abbreviation Examples
cache:flush c:f, ca:fl, cach:flu
setup:upgrade s:up, set:up, setup:u
setup:static-content:deploy s:s:d, set:sta:dep
indexer:reindex i:r, ind:rei
Rule: Abbreviation must be unique. If it matches multiple commands, you'll get an error listing all matches.

Essential Commands

1. Setup & Installation

setup:install

Purpose: Install Magento via CLI (preferred over /setup URL)

bin/magento setup:install \
    --base-url=https://example.com/ \
    --db-host=localhost \
    --db-name=magento \
    --db-user=root \
    --db-password=db_password \
    --admin-firstname=John \
    --admin-lastname=Doe \
    --admin-email=john@example.com \
    --admin-user=admin \
    --admin-password=admin123
setup:upgrade

Purpose: Run setup install scripts and synchronize DB schema

bin/magento setup:upgrade
Speed Up Development:
bin/magento setup:upgrade --keep-generated

Use --keep-generated when NOT modifying plugins or extension attributes. Speeds up by skipping code generation.

setup:di:compile

Purpose: Generate DI configuration and code

bin/magento setup:di:compile

Generates code in generated/ directory. Required after adding plugins or modifying constructor dependencies.

setup:static-content:deploy

Purpose: Build static content for production

bin/magento setup:static-content:deploy en_US
⚠️ Production Mode Only!

This command is typically for production mode. In developer mode, use dev:source-theme:deploy instead.

2. Module Management

module:status

Purpose: Check if modules are enabled or disabled

bin/magento module:status

Lists all modules showing enabled/disabled status. Essential for troubleshooting "why aren't my changes working?"

module:enable

Purpose: Enable one or more modules

bin/magento module:enable Vendor_Module
bin/magento module:enable Vendor_A Vendor_B
After enabling: Always run setup:upgrade!
module:disable

Purpose: Disable one or more modules

bin/magento module:disable Vendor_Module

3. Cache Management

Cache commands are among the most frequently used during development.

cache:flush

Purpose: Flush all cache types

bin/magento cache:flush
# Abbreviation
bin/magento c:f
cache:clean

Purpose: Clean specific cache types

bin/magento cache:clean
bin/magento cache:clean config layout
cache:enable / cache:disable

Purpose: Enable or disable cache types

bin/magento cache:enable
bin/magento cache:disable full_page block_html
Development Best Practice:

Develop with as many caches enabled as possible for faster response times. Disable only caches you're actively modifying (e.g., full_page, block_html, layout when building themes).

4. Indexing

indexer:info

Purpose: List all available indexers

bin/magento indexer:info

Shows all indexer codes and names. Use these codes with other indexer commands.

indexer:status

Purpose: Check indexer status and when last run

bin/magento indexer:status

Shows status (Ready/Reindex required), mode (Update on Save/Schedule), and last update time.

indexer:reindex

Purpose: Reindex all or specific indices

bin/magento indexer:reindex
bin/magento indexer:reindex catalog_product_price
bin/magento indexer:reindex catalog_product_price catalogsearch_fulltext
Tip: Use indexer:info to see all available index codes first.
indexer:set-mode

Purpose: Set indexer mode (realtime or schedule)

bin/magento indexer:set-mode realtime
bin/magento indexer:set-mode schedule catalog_product_price
Performance Warning:

"Update on Save" (realtime) can bring local machines to a standstill with large catalogs. Use "Update on Schedule" but ensure cron is running!

5. Development Tools

dev:source-theme:deploy

Purpose: Create symlinks for LESS/CSS files (Developer mode)

bin/magento dev:source-theme:deploy

Establishes symlinks from module source files to pub/static. Keeps LESS files always up to date. Also rebuilds CSS for themes.

deploy:mode:set

Purpose: Switch between developer/production/default modes

bin/magento deploy:mode:set developer
bin/magento deploy:mode:set production
deploy:mode:show

Purpose: Display current mode

bin/magento deploy:mode:show

6. Admin User Management

admin:user:create

Purpose: Create admin user or reset password

bin/magento admin:user:create \
    --admin-user=admin \
    --admin-password=admin123 \
    --admin-email=admin@example.com \
    --admin-firstname=John \
    --admin-lastname=Doe

Useful when locked out or switching between systems.

Finding Available Commands

To see all available commands:

bin/magento

To see help for a specific command:

bin/magento help setup:upgrade
bin/magento setup:upgrade --help
Troubleshooting:

If a common command says "not available", there's likely a problem. Run bin/magento alone and the error will appear.

Development Cycle Usage

Typical Development Workflow

Starting a New Module:
  1. Create module files
  2. module:enable Vendor_Module
  3. setup:upgrade
  4. cache:flush
After Code Changes:
  1. Modified DI? setup:di:compile
  2. Modified schema? setup:upgrade
  3. Modified templates? Just refresh
  4. Modified config? cache:clean config
Theme Development:
  1. dev:source-theme:deploy
  2. Disable full_page cache
  3. Make changes
  4. Refresh browser
Before Deployment:
  1. deploy:mode:set production
  2. setup:di:compile
  3. setup:static-content:deploy
  4. indexer:reindex

Exam Tips

Key Points to Remember

  • Commands can be abbreviated to any unique combination
  • setup:upgrade is required after enabling modules or schema changes
  • --keep-generated speeds up setup:upgrade when not modifying plugins
  • setup:static-content:deploy is for production, dev:source-theme:deploy for development
  • Always run setup:upgrade after module:enable
  • cache:flush clears all caches
  • Indexer modes: realtime (update on save) or schedule (update on schedule)
  • Run bin/magento alone to see all available commands
  • CLI requires server access - it's a trusted environment
  • Use indexer:info to see all available index codes and names