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=admin123
setup:upgrade
Purpose: Run setup install scripts and synchronize DB schema
bin/magento setup:upgrade
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
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
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
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
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
"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
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
- Create module files
module:enable Vendor_Modulesetup:upgradecache: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 productionsetup:di:compilesetup:static-content:deployindexer: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 pluginssetup: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