Magento CLI Commands: Complete Guide and Reference Table

Magento CLI Commands: Complete Guide and Reference Table

[Updated: March 16, 2026]

Your Magento admin panel handles basic tasks. Cache flushes, reindexing, and deployments run faster and more reliable through the command line.

This guide covers every essential Magento 2.4.8 CLI command, a full reference table, common errors, and best practices for production stores.

Best Magento Hosting now

Key Takeaways

  • The Magento CLI provides 145 commands in Magento 2.4.8 for cache, indexing, deployment, and system management.
  • CLI operations run faster and are more reliable than admin panel equivalents for production environments.
  • Magento 2.4.8 requires PHP 8.3 or 8.4, MySQL 8.4 LTS, and OpenSearch 2.19.
  • Common CLI errors stem from wrong PHP versions, file permission issues, or running commands as the wrong system user.
  • Managed hosting providers pre-configure SSH access and CLI permissions, removing the most common barriers to CLI usage.

TL;DR

Magento CLI = A command line tool built into every Magento 2 installation at bin/magento. It provides 145 commands for cache management, indexing, deployment, module control, and system configuration.

Perfect for: Store administrators, DevOps engineers, developers running Magento 2.4.x in production

Not ideal for: Non-technical store owners without SSH access or managed hosting support

What is the Magento CLI?

The Magento CLI (Command Line Interface) is a text-based tool that ships with every Magento 2 installation. It lives in the <project-root>/bin/ directory and provides direct control over cache, indexes, modules, cron jobs, deployment modes, and system configuration.

Magento 2.4.8 includes 145 CLI commands. Each command handles a specific operation that would take longer through the admin panel or require direct database manipulation.

The CLI is the preferred method for production operations. Cache flushes, full reindexes, and static content deployment all complete faster through CLI than through the admin panel. Automated CI/CD pipelines depend on CLI commands for zero-downtime deployments.

How to Access Magento CLI

Navigate to your Magento root directory via SSH and run:

php bin/magento

This outputs the full help page with all available commands. The php prefix is optional if your system's PATH includes the correct PHP binary.

To get help for a specific command:

php bin/magento help setup:upgrade

Command Naming Convention

Every CLI command follows the format: group:[subject:]action

  • Group: Category of related commands (e.g., cache, indexer, setup)
  • Subject: Optional context (e.g., static-content in setup:static-content:deploy)
  • Action: The operation to perform (e.g., clean, reindex, deploy)

Magento also supports command abbreviations. You can type s:up instead of setup:upgrade or c:c instead of cache:clean, as long as the abbreviation is unambiguous.

Prerequisites

Before running CLI commands, verify these requirements:

  1. SSH access to your Magento server. Managed hosting providers include this by default.
  2. Correct PHP version: Magento 2.4.8 requires PHP 8.3 or 8.4. Check your version:
php -v
  1. Correct system user: Run CLI commands as the Magento file system owner, not as root. Wrong user context causes permission errors that break the store.
  2. Magento installed and functional: The bin/magento binary requires a working Magento installation with database connectivity.

If you encounter a "PHP Parse error," you are running the wrong PHP version. On servers with multiple PHP installations, specify the full path:

/usr/bin/php8.3 bin/magento

Essential CLI Commands

Cache Management

Magento uses multiple cache types: configuration, layout, block HTML, full page, and more. CLI cache operations are faster and more thorough than admin panel cache management.

Check cache status:

bin/magento cache:status

Clean specific cache types (removes outdated entries):

bin/magento cache:clean config full_page

Flush all caches (removes everything, forces full rebuild):

bin/magento cache:flush

Enable or disable specific cache types:

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

For a complete walkthrough, see our Magento 2 cache management guide.

Indexer Management

Indexers synchronize storefront data with the database. This includes product prices, stock status, catalog search, and category assignments.

View all indexers and their status:

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

Set indexer mode (realtime updates vs scheduled):

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

Reindex all or specific indexers:

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

For production stores with large catalogs, schedule reindexing during low-traffic hours. Full reindex operations on catalogs with 100K+ products can take 30 minutes or longer. See our reindexing guide for optimization strategies.

Static Content Deployment

Static view files (CSS, JavaScript, images, fonts) must be deployed before they are served in production. This step compiles and optimizes assets for each configured store view and theme.

Deploy for all locales:

bin/magento setup:static-content:deploy

Deploy for specific locales and exclude themes:

bin/magento setup:static-content:deploy en_US de_DE --exclude-theme Magento/blank

Use parallel jobs to speed up deployment:

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

For detailed deployment options, read our static content deployment tutorial.

Maintenance Mode

Maintenance mode restricts frontend access during updates, migrations, or major configuration changes.

Enable maintenance mode:

bin/magento maintenance:enable

Allow specific IP addresses to bypass maintenance mode:

bin/magento maintenance:allow-ips 192.168.1.100 10.0.0.50

Disable maintenance mode:

bin/magento maintenance:disable

Check current status:

bin/magento maintenance:status

Module Management

List all modules and their status:

bin/magento module:status
bin/magento module:status --enabled
bin/magento module:status --disabled

Enable or disable modules:

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

After enabling a module, run the setup upgrade:

bin/magento setup:upgrade

Cron Jobs

Magento relies on cron jobs for scheduled tasks: index updates, email sending, sitemap generation, and currency rate updates.

Install Magento crontab entries:

bin/magento cron:install

Run cron jobs on demand:

bin/magento cron:run

Remove Magento crontab entries:

bin/magento cron:remove

Admin User Management

Create admin accounts without accessing the admin panel:

bin/magento admin:user:create \
  --admin-user=admin \
  --admin-password=SecureP@ss123 \
  --admin-email=admin@example.com \
  --admin-firstname=John \
  --admin-lastname=Smith

Unlock a locked admin account:

bin/magento admin:user:unlock admin

Security Features

Reset two-factor authentication for a specific admin user:

bin/magento security:tfa:reset admin google

Disable reCAPTCHA for admin login (useful during development):

bin/magento security:recaptcha:disable-for-user-login

For a complete guide on applying security patches through the CLI, see our dedicated tutorial.

Deploy Modes

Magento supports three operating modes:

Mode Purpose Performance
Default Initial setup Basic
Developer Local development, debugging Slow (no caching)
Production Live stores Optimized

Check current mode:

bin/magento deploy:mode:show

Switch to production mode:

bin/magento deploy:mode:set production

Production mode enables full page cache, disables error display, and serves pre-compiled static assets.

Essential Command Reference

The most-used Magento 2.4.8 CLI commands in one table:

Command Description
setup:upgrade Apply database schema and data updates
setup:di:compile Generate dependency injection configuration
setup:static-content:deploy Deploy static view files
cache:clean Clean expired cache entries
cache:flush Flush all cache storage
cache:status Show cache type status
cache:enable / cache:disable Toggle cache types
indexer:reindex Rebuild indexes
indexer:status Show indexer status
indexer:set-mode Set realtime or schedule mode
cron:install / cron:remove Manage crontab entries
cron:run Execute pending cron jobs
module:enable / module:disable Toggle modules
module:status List module status
maintenance:enable / maintenance:disable Toggle maintenance mode
maintenance:allow-ips Whitelist IPs during maintenance
deploy:mode:set Switch operating mode
deploy:mode:show Show current mode
admin:user:create Create admin account
admin:user:unlock Unlock admin account
config:set Set configuration values
config:show Display configuration
store:list List all stores and views
store:website:list List all websites
catalog:images:resize Regenerate catalog images
catalog:product:attributes:cleanup Remove unused product attributes
queue:consumers:start Start message queue consumers
queue:consumers:list List available queue consumers
i18n:collect-phrases Collect translation phrases
i18n:pack Create translation packages
info:dependencies:show-modules Show module dependencies
sampledata:deploy Install sample data
encryption:payment-data:update Re-encrypt payment data

Common CLI Errors and How to Fix Them

Permission Denied

Error: Permission denied or Cannot create directory

Cause: Running CLI as the wrong system user. Magento files are owned by the web server user (e.g., www-data, nginx, or a custom user).

Fix: Switch to the correct user before running commands:

sudo -u www-data php bin/magento cache:clean

Or fix ownership after running as root:

chown -R www-data:www-data var/ generated/ pub/static/

PHP Version Mismatch

Error: PHP Parse error: syntax error or This application requires PHP 8.3

Cause: The server's default PHP version does not match Magento's requirements.

Fix: Specify the correct PHP binary:

/usr/bin/php8.3 bin/magento setup:upgrade

On managed hosting, the correct PHP version is pre-configured and mapped to the default php command.

Out of Memory

Error: Allowed memory size of X bytes exhausted

Cause: Operations like DI compilation and full reindex need more memory than the PHP default.

Fix: Increase memory limit for the command:

php -d memory_limit=2G bin/magento setup:di:compile

Stuck Deployment

Error: Unable to proceed: another process is running or deployment hangs

Cause: A previous deployment crashed and left a lock file.

Fix: Remove the lock file and retry:

rm var/.maintenance.flag
rm var/.setup_cronjob_status
bin/magento setup:static-content:deploy

Module Conflicts After Upgrade

Error: Module X setup version X.X.X is newer than the database version

Cause: Module database schemas are out of sync after an update.

Fix: Run the upgrade sequence to synchronize:

bin/magento setup:upgrade
bin/magento setup:di:compile
bin/magento setup:static-content:deploy

Best Practices for Magento CLI

  1. Run setup:upgrade after every module change. Module enable/disable operations require a database schema sync. Skipping this step causes silent failures.

  2. Use cache:clean over cache:flush in production. Clean removes expired entries. Flush empties everything and forces a full rebuild, which causes temporary performance drops.

  3. Deploy static content with the --jobs flag. Multi-threaded deployment (--jobs=4) cuts deployment time in half on multi-core servers.

  4. Set indexers to "schedule" mode in production. Realtime indexing triggers on every catalog change and slows admin operations. Scheduled mode batches updates via cron.

  5. Never run CLI commands as root. Root-created files become inaccessible to the web server. Use sudo -u <magento-user> instead.

  6. Use maintenance mode during upgrades. This prevents customers from seeing errors or incomplete data during schema changes and static content deployment.

  7. Compile DI after every code change. Run setup:di:compile after module installation, class modifications, or plugin additions. Production mode requires compiled DI to function.

  8. Back up before destructive operations. Create database and file system backups before major version upgrades using your hosting provider's backup tools or standard server-level scripts.

  9. Use command abbreviations for speed. c:f for cache:flush, s:up for setup:upgrade, i:rei for indexer:reindex. Magento resolves unambiguous abbreviations.

  10. Monitor cron execution. Check the cron_schedule table for stuck or missed jobs: SELECT * FROM cron_schedule WHERE status = 'error' ORDER BY scheduled_at DESC LIMIT 20;

Why Managed Hosting Matters for CLI Access

CLI access requires SSH, correct PHP configuration, proper file permissions, and a server environment that matches Magento's system requirements. On self-managed servers, configuring these prerequisites takes hours. Troubleshooting permission issues is the most common barrier to productive CLI usage.

Managed Magento hosting eliminates these obstacles. SSH access comes pre-configured with the correct user context. PHP 8.3 or 8.4 is installed and mapped to the default php command. File permissions are set for the web server user. CLI commands work without additional server configuration.

This matters for production stores where CLI operations are part of the daily workflow: cache management, deployment pipelines, and scheduled maintenance all depend on reliable CLI access.

FAQ

1. What PHP version does the Magento 2.4.8 CLI require?

Magento 2.4.8 requires PHP 8.3 or PHP 8.4. PHP 8.2 is available for upgrade-path use only and is not recommended for new installations. Verify your PHP version with php -v before running any CLI commands.

2. Can I run Magento CLI commands without SSH access?

No. The Magento CLI requires direct server access through SSH. If your hosting provider does not offer SSH access, you cannot use CLI commands. Managed hosting providers include SSH access as a standard feature.

3. What is the difference between cache clean and cache flush?

cache:clean removes expired and outdated cache entries while preserving valid cached data. cache:flush empties the entire cache storage and forces a complete rebuild. Use cache:clean for routine maintenance and cache:flush after major configuration changes.

4. How do I check which Magento version is installed?

Run php bin/magento --version to display the current Magento version. This shows the exact version number including patch level.

5. Why does setup:upgrade fail with permission errors?

Permission errors during setup:upgrade occur when the command runs under a different user than the Magento file system owner. Run the command as the correct user with sudo -u www-data php bin/magento setup:upgrade.

6. Can I undo a module disable operation?

Yes. Run bin/magento module:enable Vendor_Module followed by bin/magento setup:upgrade to re-enable a disabled module. The module's data and configuration remain in the database unless you ran module:uninstall.

7. How do I create a custom CLI command in Magento 2?

Create a custom command by extending Symfony\Component\Console\Command\Command in your module's Console/Command/ directory. Register the command in your module's di.xml under the Magento\Framework\Console\CommandListInterface type. Run setup:di:compile to make the command available.

8. What database does Magento 2.4.8 support?

Magento 2.4.8 supports MySQL 8.4 LTS and MariaDB 11.4 LTS. For search, it requires OpenSearch 2.19. Elasticsearch 8.17 is still listed for on-premise installations but is deprecated in favor of OpenSearch. Valkey 8.x was added as a new cache backend option alongside Redis 7.2.

9. How long does static content deployment take?

Deployment time depends on the number of locales, themes, and static assets. A single locale with one theme deploys in 2 to 5 minutes. Multiple locales and themes can take 15 to 30 minutes. Use the --jobs flag to parallelize and cut deployment time.

10. Is there a way to test CLI commands without affecting the live store?

Yes. Set up a staging environment or use a dedicated test server. Run deploy:mode:set developer on your test environment for verbose error output. Enable maintenance mode on the live store before running commands that affect the database or file system.

Summary

The Magento CLI is the fastest and most reliable way to manage a Magento 2 store. From cache management and indexing to deployment and security configuration, CLI commands complete operations that the admin panel handles slower or cannot handle at all.

Magento 2.4.8 ships with 145 commands covering every aspect of store management. Master the essential commands in this guide, follow the best practices, and troubleshoot common errors with confidence.

For production stores where CLI operations are critical, pre-configured hosting provides the server environment that makes every command work without setup friction.

CEO & Co-Founder

Raphael Thiel co-founded MGT-Commerce in 2011 together with Stefan Wieczorek and has built it into a leading Magento hosting provider serving 5,000+ customers on AWS. With 25+ years in e-commerce and cloud infrastructure, he oversees hosting architecture for enterprise clients. He also co-founded CloudPanel, an open-source server management platform.


Get the fastest Magento Hosting! Get Started