Powerful digital products, engineered in Kerala for organisations everywhere.
+91 95399 51353 opsintech@icloud.com Privacy + data protection
← Back to the journal Magento CLI

Magento 2 CLI command reference for daily development and deployment

Copy-ready Magento commands for maintenance mode, cache, setup upgrades, compilation, static content, indexers, and local admin users—with clear safety notes.

Editorial image for Magento 2 CLI command reference for daily development and deployment
Magento CLI / OpsinTech insight
01

Step 1: inspect the current state

Start with read-only status commands. Run Magento CLI commands as the application filesystem owner and from the Magento root.

Show deployment mode

Reports whether Magento is in default, developer, or production mode.

bin/magento deploy:mode:show
When to use itCheck before choosing a static-content or debugging workflow.

Check maintenance mode

Reports whether maintenance mode is enabled and any exempt IP addresses.

bin/magento maintenance:status
When to use itUse before and after a planned deployment.

Check caches and indexers

Shows disabled cache types and indexers that require attention.

bin/magento cache:status
bin/magento indexer:status
When to use itUse after deployment or while diagnosing stale storefront data.
02

Step 2: control maintenance mode

Maintenance mode returns a 503 response to most visitors while deployment work is in progress. Plan monitoring and a rollback path before enabling it in production.

Enable maintenance mode

Places the application in maintenance mode so storefront traffic does not reach an incomplete deployment.

bin/magento maintenance:enable
When to use itEnable immediately before a production change that cannot safely run with live traffic.

Allow a deployment IP

Allows a reviewed IP address to access the site during maintenance.

bin/magento maintenance:allow-ips <trusted-ip>
When to use itUse for a deployment operator or smoke-test service; remove obsolete exemptions afterward.

Disable maintenance mode

Restores normal application access after deployment checks pass.

bin/magento maintenance:disable
When to use itRun only after schema updates, compilation, static assets, cache, and smoke tests complete.
03

Step 3: apply schema and generated-code changes

The exact deployment order depends on your hosting model. Back up first, use the application’s release process, and do not improvise directly on production.

Apply module setup changes

Updates module registration and applies declarative schema and data changes.

bin/magento setup:upgrade
When to use itRun after deploying a new or changed module that affects setup.

Compile dependency injection

Generates dependency-injection factories, proxies, interceptors, and related compiled code.

bin/magento setup:di:compile
When to use itUse as part of a production build or after class wiring changes.

Deploy static storefront files

Generates static view files for the named locales. Remove locales the store does not use.

bin/magento setup:static-content:deploy -f en_US en_GB
When to use itUse during a production build when themes or frontend assets changed.
04

Step 4: choose cache clean or cache flush

Cleaning removes Magento cache entries for selected types. Flushing empties the underlying cache storage and can affect other applications if the storage is shared.

Clean Magento caches

Removes Magento-managed cache entries while leaving unrelated shared-cache data alone.

bin/magento cache:clean
When to use itPrefer this after configuration, layout, or application code changes.

Clean selected cache types

Cleans only the specified cache types for a more targeted operation.

bin/magento cache:clean config layout block_html
When to use itUse when you know which cache types the change affects.

Flush cache storage

Purges the cache storage used by Magento, potentially including non-Magento entries.

bin/magento cache:flush
When to use itReserve for cases where a normal clean cannot remove stale storage entries.
CautionBroad operation: understand whether the cache backend is shared before running it.
05

Step 5: inspect and rebuild indexers

A complete reindex can take time on a large catalogue. Check status first and prefer scheduled indexing where it fits the store’s operating model.

List indexers and modes

Lists indexer identifiers and whether each updates on save or by schedule.

bin/magento indexer:info
bin/magento indexer:show-mode
When to use itUse before targeting a single indexer or changing the indexing strategy.

Check indexer status

Reports valid, invalid, suspended, or working states.

bin/magento indexer:status
When to use itUse after imports, module changes, or deployment.

Reindex one or all indexers

The first command rebuilds a selected indexer; the second rebuilds all indexers.

bin/magento indexer:reindex <indexer-id>
bin/magento indexer:reindex
When to use itTarget a known invalid indexer where possible to reduce work.
06

Step 6: create a local administrator safely

Use this only in an authorized environment. Values in angle brackets are placeholders and must never be copied as real credentials.

Create an administrator

Creates a Magento Admin user with the supplied identity fields.

bin/magento admin:user:create --admin-user=<admin-user> --admin-password=<strong-password> [email protected] --admin-firstname=<first-name> --admin-lastname=<last-name>
When to use itUse a unique local account and enter secrets through an approved secret-handling workflow.
CautionDo not save real administrator passwords in scripts, tickets, shell history, or shared command notes.
REF

Further reading

Related OpsinTech solutions
ServiceE-commerce Development ServiceManaged Web Hosting & Cloud