Introduction
Magento 2 CLI commands are the fastest way to manage a Magento store. With one line in the terminal, you can clear the cache, reindex products, deploy a new theme, enable maintenance mode, or create an admin user. Many tasks, like compiling code or switching to production mode, can only be done from the command line.
The Magento command line tool is called bin/magento, and it ships with more than a hundred commands. You do not need to learn all of them. In this guide, we cover the 15 Magento 2 commands that developers and store administrators use almost every day, with examples and simple explanations.
This is Day 3 of our Magento and eCommerce series. In Day 1, we installed Magento 2.4.9, and in Day 2, we explored the admin panel. Today, we move to the terminal.
Key takeaways:
- Run all Magento 2 CLI commands from the Magento root folder as the file system owner, never as root.
- After installing or updating code, run setup:upgrade, setup:di:compile, setup:static-content:deploy, and cache:flush.
- Use indexer:reindex and cache:clean to fix most “my change is not showing” problems.
- Put the store in maintenance mode before any deployment on a live site.
On This Page
Why Magento 2 CLI Commands Matter
The admin panel is great for store settings, but developers need the command line. Magento 2 CLI commands are faster, can be scripted, and work even when the admin panel is down. They are also the only way to run some tasks, such as code compilation, static content deployment, and database schema upgrades.
Knowing the right Magento command line tools also makes deployments safer. A clear, repeatable set of commands means every release follows the same steps, with fewer mistakes and less downtime.
Prerequisites for Using Magento 2 CLI Commands
Before you start, make sure you have:
- A working Magento 2 store: See our Magento 2 setup guide to install one.
- SSH access to the server where Magento is installed.
- The file system owner account: In our series, this is the magento user.
- Basic Linux knowledge: Moving between folders and running commands.
Switch to the file system owner and go to the Magento root folder before running any command:
sudo su - magento cd /var/www/magento2
Note: Running Magento 2 CLI commands as the root user creates files that the web server cannot write to. This causes permission errors on the storefront. Always use the file system owner.
15 Magento 2 CLI Commands with Examples
Here is a quick cheat sheet of the 15 Magento 2 commands covered in this guide.
| No. | Command | What it does |
|---|---|---|
| 1 | list / help | Shows all commands and their options |
| 2 | setup:upgrade | Updates the database schema and data after code changes |
| 3 | setup:di:compile | Compiles dependency injection code |
| 4 | setup:static-content:deploy | Deploys CSS, JS, and images |
| 5 | cache:clean / cache:flush | Clears the Magento cache |
| 6 | indexer:reindex | Rebuilds the store indexes |
| 7 | deploy:mode:set | Switches between developer and production mode |
| 8 | maintenance:enable | Turns maintenance mode on or off |
| 9 | module:status | Lists, enables, or disables modules |
| 10 | cron:install / cron:run | Sets up and runs Magento cron jobs |
| 11 | config:set / config:show | Changes or reads store settings |
| 12 | admin:user:create | Creates or unlocks admin users |
| 13 | setup:db:status | Checks whether the database needs an upgrade |
| 14 | catalog:images:resize | Generates product image sizes |
| 15 | queue:consumers:start | Runs message queue consumers |

1. List All Commands: bin/magento list
Start here when you forget a command name. The list command shows every available command, grouped by namespace.
bin/magento list bin/magento list cache bin/magento help indexer:reindex
Use help with any command to see its arguments and options.
2. Upgrade the Database: bin/magento setup:upgrade
Run this command after you install, update, or enable a module or extension. It updates the database schema and data to match your code.
bin/magento setup:upgrade
Note: setup:upgrade clears generated code. On production, add --keep-generated only if you have already compiled the code in your deployment process.
3. Compile the Code: bin/magento setup:di:compile
This command generates factories, proxies, and interceptors that Magento needs to run. It is required in production mode after any code change.
bin/magento setup:di:compile
4. Deploy Static Content: bin/magento setup:static-content:deploy
This command copies and builds CSS, JavaScript, fonts, and images into the pub/static folder for each theme and language.
bin/magento setup:static-content:deploy -f en_US en_IN
The -f (force) option is needed when the store is in developer or default mode. Add every language your store views use, for example en_US and en_IN.
5. Clean and Flush the Cache: bin/magento cache
The cache commands are the ones you will use most often.
bin/magento cache:status bin/magento cache:clean bin/magento cache:flush bin/magento cache:clean config full_page
- cache:clean deletes items from enabled Magento cache types only. Try this first.
- cache:flush purges the whole cache storage, which can affect other apps that share the same storage, such as Valkey.
6. Reindex Data: bin/magento indexer
Indexers turn your product, category, price, and stock data into fast lookup tables. If prices or products do not show correctly on the storefront, reindex.
bin/magento indexer:status bin/magento indexer:reindex bin/magento indexer:reindex catalogsearch_fulltext bin/magento indexer:set-mode schedule
Note: For live stores, use schedule mode (Update by Schedule) so cron updates indexes in the background instead of slowing down every save in the admin.
7. Switch Deploy Modes: bin/magento deploy:mode
Magento has developer, default, and production modes. Use developer mode while building, and production mode for live stores.
bin/magento deploy:mode:show bin/magento deploy:mode:set developer bin/magento deploy:mode:set production
Switching to production mode automatically compiles the code and deploys static content.
8. Enable Maintenance Mode: bin/magento maintenance
Maintenance mode shows a “Service Unavailable” page to visitors while you work on the store. You can allow your own IP address so you can still test the site.
bin/magento maintenance:enable --ip=203.0.113.10 bin/magento maintenance:status bin/magento maintenance:disable
Want a branded maintenance page? Read our guide on how to enable maintenance mode in Magento and customize the maintenance page.
9. Manage Modules: bin/magento module
Use these commands to check, enable, or disable modules and extensions.
bin/magento module:status bin/magento module:disable Vendor_Module bin/magento module:enable Vendor_Module bin/magento setup:upgrade
Replace Vendor_Module with the real module name, such as Magento_Newsletter. Always run setup:upgrade after you enable or disable a module.
10. Set Up Cron Jobs: bin/magento cron
Cron runs indexers, sends emails, and processes scheduled tasks. Install it once, then check that it is running.
bin/magento cron:install crontab -l bin/magento cron:run
11. Change Settings: bin/magento config:set and config:show
You can read and change most store settings without opening the admin panel. This is very useful in deployment scripts.
bin/magento config:show web/unsecure/base_url bin/magento config:set web/secure/use_in_frontend 1 bin/magento config:set web/secure/use_in_adminhtml 1
Note: After you change base URLs or secure settings, run bin/magento cache:clean config so Magento loads the new values.
12. Manage Admin Users: bin/magento admin:user
Create a new admin account or unlock one that was locked after too many failed logins.
bin/magento admin:user:create --admin-user=devuser --admin-password='Dev@Pass2026' --admin-email=dev@example.com --admin-firstname=Dev --admin-lastname=User bin/magento admin:user:unlock devuser bin/magento info:adminuri
For password resets, see our guide on how to reset the Magento 2 admin password using the CLI.
13. Check the Database Status: bin/magento setup:db:status
This command tells you whether your database is up to date with your code. It is a quick check before and after deployments.
bin/magento setup:db:status
Output:
All modules are up to date.
If it reports that modules need an upgrade, run bin/magento setup:upgrade.
14. Resize Product Images: bin/magento catalog:images:resize
This command creates all product image sizes defined in your theme. Run it after you import many products or change a theme, so the storefront does not resize images on the first visit.
bin/magento catalog:images:resize
15. Run Message Queue Consumers: bin/magento queue:consumers
Magento uses message queues for tasks such as bulk actions, exports, and inventory updates. You can list and start consumers from the command line.
bin/magento queue:consumers:list bin/magento queue:consumers:start exportProcessor
By default, cron starts the consumers for you. Start them manually only when you need to debug a stuck task.
Magento 2 Deployment Command Sequence
When you deploy new code or extensions to a live store, run the Magento 2 CLI commands in this order:
bin/magento maintenance:enable composer install --no-dev bin/magento setup:upgrade bin/magento setup:di:compile bin/magento setup:static-content:deploy -f en_US en_IN bin/magento cache:flush bin/magento maintenance:disable

Note: Always take a database and file backup before you deploy to a live store, and test the same commands on a staging server first.
Common Magento 2 CLI Mistakes to Avoid
- Running commands as root: This causes permission errors. Use the file system owner.
- Skipping setup:upgrade after installing a module: The storefront may show errors because the database is out of date.
- Forgetting -f in developer mode: Static content deploy will not run without it.
- Using cache:flush on shared storage without care: It can clear data that other applications use.
- Deploying without maintenance mode: Customers may see broken pages during the deployment.
Conclusion
Magento 2 CLI commands give you full control of your store from the terminal. Once you learn these 15 commands, daily tasks like clearing the cache, reindexing, and deploying updates become quick and predictable.
Quick recap:
- Use list and help to discover any Magento command.
- After code changes, run setup:upgrade, setup:di:compile, static content deploy, and cache:flush.
- Fix display issues with cache:clean and indexer:reindex.
- Use maintenance mode and a fixed deployment order for live stores.
- Always run commands as the file system owner.
Bookmark this list of Magento 2 CLI commands for your team. In the next article of this series, we will set up the store configuration: websites, stores, and store views.
FAQs
1. Where do I run Magento 2 CLI commands?
Run them from the Magento root folder (for example, /var/www/magento2) using bin/magento, logged in as the file system owner.
2. What is the difference between cache:clean and cache:flush?
cache:clean deletes items only from enabled Magento cache types. cache:flush purges the whole cache storage, which can also remove data used by other applications that share it.
3. Which command should I run after installing an extension?
Run setup:upgrade, then setup:di:compile and setup:static-content:deploy in production mode, and finally cache:flush.
4. How do I fix “One or more indexers are invalid” in Magento 2?
Run bin/magento indexer:reindex, and make sure cron is installed so indexes stay up to date in schedule mode.
5. How do I see all available Magento 2 commands?
Run bin/magento list. To see the options for one command, run bin/magento help followed by the command name.
Related Articles
- Magento 2 Setup Guide: Install Magento 2.4.9 on Ubuntu in 9 Steps
- Magento 2 Admin Panel Guide: 10 Key Sections Every Store Owner Should Know
- How to Enable Maintenance Mode in Magento and Customize the Maintenance Page
- How to Reset the Admin Password in Magento 2 Using the Command Line Interface Tool
- How to Resolve the Autoload Error While Installing Magento 2 in Ubuntu
Official Documentation
- Command-Line Tool Overview
- Manage the Cache
- Manage the Indexers
- Set the Application Mode
- Code Compiler
- Enable or Disable Maintenance Mode
- Configure and Run Cron
Talk to Magento Experts
Running Magento deployments by hand on a live store can be risky. At Pheonix Solutions, our developers build, deploy, and maintain Magento stores with safe, automated release processes.
We can help you with:
- eCommerce development on Magento 2, including custom modules and extensions.
- DevOps and cloud services to automate Magento deployments with CI/CD pipelines.
- Software maintenance and support for upgrades, reindexing issues, and performance fixes.
Need a reliable deployment process for your Magento store? Talk to our Magento experts and ship updates without downtime.
