Magento 2 Commands Cheat Sheet: 45+ bin/magento Commands Explained

Every bin/magento command you need day to day, grouped by task, with examples: cache, indexers, deployment, static content, modules, cron, admin users and troubleshooting.

Magento 2 is managed largely from the command line with bin/magento. Whether you are clearing the cache, reindexing, deploying a new release or creating an admin user, there is a command for it.

This cheat sheet groups the commands I use most often by task, with short explanations and examples. Bookmark it, you will come back to it.

All commands are run from the Magento root directory, as the file system owner (not root):

cd /var/www/magento
php bin/magento list

bin/magento list shows every available command, including those added by extensions.

Cache commands

How to clear the cache in Magento 2

bin/magento cache:clean
bin/magento cache:flush
  • cache:clean removes items from the enabled Magento cache types only. Use this first.
  • cache:flush purges the entire cache storage, including items from other applications using the same storage. Use it when clean is not enough.

Clean a single cache type

bin/magento cache:clean config layout full_page

Check, enable and disable cache types

bin/magento cache:status
bin/magento cache:enable
bin/magento cache:disable full_page

Never leave cache types disabled in production. It is one of the most common causes of a slow store (see why Magento 2 stores get slow).

Indexer commands

How to reindex in Magento 2

bin/magento indexer:reindex
bin/magento indexer:reindex catalog_product_price

Check indexer status

bin/magento indexer:status
bin/magento indexer:info

Set indexer mode

bin/magento indexer:show-mode
bin/magento indexer:set-mode schedule
bin/magento indexer:set-mode realtime catalogsearch_fulltext

schedule (Update by Schedule) is recommended for production. Reindexing then happens through cron instead of on every save.

Fix a stuck indexer

If an index stays in “processing” or “reindex required”:

bin/magento indexer:reset catalog_product_price
bin/magento indexer:reindex catalog_product_price

Setup and upgrade commands

After installing or updating a module

bin/magento setup:upgrade
bin/magento setup:di:compile
bin/magento setup:static-content:deploy -f
bin/magento cache:flush
  • setup:upgrade updates the database schema and data
  • setup:di:compile generates dependency injection code
  • setup:static-content:deploy generates CSS, JS and images for the frontend and admin

Keep generated files during upgrade

bin/magento setup:upgrade --keep-generated

Useful in deployment pipelines where code has already been compiled.

Check database status

bin/magento setup:db:status

Static content deployment

Deploy for specific languages

bin/magento setup:static-content:deploy en_US nl_NL de_DE -f

Deploy only one theme or area

bin/magento setup:static-content:deploy --area frontend --theme Hyva/default -f

Speed up deployment

bin/magento setup:static-content:deploy -f --jobs 4

The -f (force) flag is needed when you are not in production mode.

Deploy mode commands

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

Switching to production mode also compiles code and deploys static content. Use --skip-compilation if your pipeline handles that separately.

Maintenance mode

bin/magento maintenance:enable
bin/magento maintenance:disable
bin/magento maintenance:status

Allow your own IP during maintenance

bin/magento maintenance:enable --ip=203.0.113.10
bin/magento maintenance:allow-ips 203.0.113.10

Module commands

bin/magento module:status
bin/magento module:enable Vendor_Module
bin/magento module:disable Vendor_Module
bin/magento module:uninstall Vendor_Module

Run setup:upgrade after enabling or disabling modules.

Cron commands

bin/magento cron:install
bin/magento cron:run
bin/magento cron:remove

cron:install adds the Magento cron job to the crontab of the current user. If indexes, emails or scheduled imports are not running, check cron first.

Admin user commands

Create an admin user

bin/magento admin:user:create --admin-user=jane --admin-password='Str0ngPass!' [email protected] --admin-firstname=Jane --admin-lastname=Doe

Unlock an admin account

bin/magento admin:user:unlock jane

Find the admin URL

bin/magento info:adminuri

Configuration commands

bin/magento config:show web/secure/base_url
bin/magento config:set web/secure/base_url https://www.example.com/
bin/magento config:set dev/js/merge_files 0
bin/magento app:config:dump
bin/magento app:config:import

config:set --lock-env writes the value to app/etc/env.php so it cannot be changed in the admin. This is handy for environment-specific settings.

Customer and catalog commands

bin/magento customer:hash:upgrade
bin/magento catalog:images:resize
bin/magento catalog:product:attributes:cleanup

catalog:images:resize pre-generates product image sizes so the first visitor does not wait for them.

Information and troubleshooting

bin/magento --version
bin/magento info:language:list
bin/magento info:currency:list
bin/magento info:timezone:list
bin/magento store:list
bin/magento store:website:list

Typical command sequences

Standard deployment

bin/magento maintenance:enable
composer install --no-dev
bin/magento setup:upgrade --keep-generated
bin/magento setup:di:compile
bin/magento setup:static-content:deploy en_US nl_NL -f --jobs 4
bin/magento cache:flush
bin/magento maintenance:disable

“Something looks wrong after a change”

rm -rf generated/code/* var/view_preprocessed/* pub/static/frontend/*
bin/magento setup:di:compile
bin/magento setup:static-content:deploy -f
bin/magento cache:flush

Be careful with rm -rf and never delete pub/static/.htaccess.

Frequently asked questions

What is the difference between cache:clean and cache:flush?

cache:clean removes Magento’s own enabled cache items. cache:flush empties the whole cache storage, which can also affect other applications sharing it (for example a shared Redis database).

Why do I get “Permission denied” when running bin/magento?

You are probably running as the wrong user. Run commands as the file system owner (often www-data or a deploy user), never as root, otherwise generated files get the wrong owner.

Do I need setup:di:compile in developer mode?

No. In developer mode, code is generated on demand. In production mode it is required.

How do I see which command an extension added?

Run bin/magento list and look for commands with the vendor’s prefix.

Need help with Magento?

From slow deployments to broken indexers, I help teams run Magento 2 smoothly and fast. See my Magento 2 and Hyvä service or request support.