Magento CLI Commands
Understanding bin/magento commands in the development cycle.
CLI Command Categories
CLI Basics
Why Use the CLI?
bin/magento provides an easy way to interact with Magento during development.
- 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 | 
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=admin123setup:upgrade
Purpose: Run setup install scripts and synchronize DB schema
bin/magento setup:upgradebin/magento setup:upgrade --keep-generatedUse --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:compileGenerates 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_USThis 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:statusLists 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_Bsetup:upgrade!
    module:disable
Purpose: Disable one or more modules
bin/magento module:disable Vendor_Module3. 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:fcache:clean
Purpose: Clean specific cache types
bin/magento cache:clean
bin/magento cache:clean config layoutcache:enable / cache:disable
Purpose: Enable or disable cache types
bin/magento cache:enable
bin/magento cache:disable full_page block_htmlDevelop 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:infoShows 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:statusShows 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_fulltextindexer: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"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:deployEstablishes 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 productiondeploy:mode:show
Purpose: Display current mode
bin/magento deploy:mode:show6. 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=DoeUseful when locked out or switching between systems.
Finding Available Commands
To see all available commands:
bin/magentoTo see help for a specific command:
bin/magento help setup:upgrade
bin/magento setup:upgrade --helpIf 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
- Create module files
- module:enable Vendor_Module
- setup:upgrade
- cache:flush
- Modified DI? setup:di:compile
- Modified schema? setup:upgrade
- Modified templates? Just refresh
- Modified config? cache:clean config
- dev:source-theme:deploy
- Disable full_page cache
- Make changes
- Refresh browser
- deploy:mode:set production
- setup:di:compile
- setup:static-content:deploy
- indexer:reindex
Exam Tips
Key Points to Remember
- Commands can be abbreviated to any unique combination
- setup:upgradeis required after enabling modules or schema changes
- --keep-generatedspeeds up setup:upgrade when not modifying plugins
- setup:static-content:deployis for production,- dev:source-theme:deployfor development
- Always run setup:upgradeaftermodule:enable
- cache:flushclears all caches
- Indexer modes: realtime (update on save) or schedule (update on schedule)
- Run bin/magentoalone to see all available commands
- CLI requires server access - it's a trusted environment
- Use indexer:infoto see all available index codes and names
