# Magento command-line reference

Magento 2 (Adobe Commerce) ships a command-line interface (CLI) at `bin/magento`. You run it over SSH to install modules, clear caches, rebuild indexes and switch deployment modes. This page groups the common commands by task. For where the files live and the scheduled jobs, see [Magento reference](reference.md).

## How to run it

Connect over [SSH](../../platform/hosts/ssh.md), change into the project root, then call the tool with PHP:

```bash
cd ~/public_html
php bin/magento <command>
```

Here `~` is your system user's home directory (for example `/var/www/prod/`). Run every `bin/magento` command from `~/public_html`.

> [!NOTE]
> To run a command with a specific Portable Hypertext Preprocessor (PHP) version, call that version's binary directly. Each installed version has its own binary at `/usr/bin/php<version>`, for example:
> ```bash
> /usr/bin/php8.4 bin/magento setup:upgrade
> ```
> See [How to switch PHP version](../../technologies/php/switch-php-version.md).

Run `php bin/magento list` for the full command list, and `php bin/magento help <command>` for the options of a single command.

## Setup and maintenance

| Command | What it does |
| --- | --- |
| `setup:install` | Installs Magento with DB and admin configuration. |
| `setup:uninstall` | Uninstalls Magento and removes configuration. |
| `setup:upgrade` | Applies DB schema/data changes from modules. |
| `setup:upgrade --keep-generated` | Keeps generated code during upgrade (for production). |
| `setup:di:compile` | Compiles dependency injection code. |
| `setup:static-content:deploy` | Deploys static view files for frontend. |
| `setup:static-content:deploy -f` | Forces deployment even in developer mode. |
| `setup:config:set` | Sets configuration values like DB or admin URL. |
| `setup:db:status` | Shows database upgrade status. |
| `setup:db:status --show-config` | Shows current DB connection settings. |
| `maintenance:enable` / `maintenance:disable` / `maintenance:status` | Enables, disables maintenance mode, or shows its status. |

## Cache management

| Command | What it does |
| --- | --- |
| `cache:clean` | Clears enabled cache types. |
| `cache:flush` | Clears all cache backends (e.g., Redis). |
| `cache:enable` / `cache:disable` | Enables or disables specified cache types. |
| `cache:status` | Displays cache types and their status. |

## Index management

| Command | What it does |
| --- | --- |
| `indexer:reindex` | Rebuilds indexers (e.g. product/category data). |
| `indexer:reindex catalogsearch_fulltext` | Reindexes product search data. |
| `indexer:status` | Shows indexer status. |
| `indexer:reset` | Resets indexers that failed. |
| `indexer:info` | Lists all indexers. |
| `indexer:show-mode` | Displays indexer mode (schedule/realtime). |
| `indexer:set-mode {schedule\|realtime} [indexer]` | Sets mode for a specific indexer. |

## Module management

| Command | What it does |
| --- | --- |
| `module:status` | Lists all modules and their status. |
| `module:enable <Module_Name>` | Enables a module. |
| `module:disable <Module_Name>` | Disables a module. |
| `module:uninstall <Module_Name>` | Uninstalls a module and optionally removes its data. |

## Admin users

| Command | What it does |
| --- | --- |
| `admin:user:create` | Creates a new admin user. |
| `admin:user:unlock <username>` | Unlocks a locked admin account. |
| `admin:user:delete <username>` | Deletes an admin user. |

## Security

| Command | What it does |
| --- | --- |
| `security:passwords:upgrade` | Upgrades customer password hash format. |
| `security:hash:upgrade` | Upgrades internal hash algorithms for better security. |

## Deployment mode and developer tools

| Command | What it does |
| --- | --- |
| `deploy:mode:show` | Shows current deployment mode. |
| `deploy:mode:set {developer\|production\|default}` | Changes deployment mode. |
| `deploy:mode:set production --skip-compilation` | Skips DI compilation during mode switch. |
| `dev:profiler:enable` / `dev:profiler:disable` | Enables or disables the performance profiler. |
| `dev:template-hints:enable` / `dev:template-hints:disable` | Displays or hides template hints in frontend. |
| `dev:source-theme:deploy` | Deploys source files (e.g. LESS) for custom themes. |

## Store configuration

| Command | What it does |
| --- | --- |
| `config:set <path> <value>` | Sets a configuration value. |
| `config:set catalog/search/engine elasticsearch7` | Sets Elasticsearch as the search engine. |
| `config:show <path>` | Shows a configuration value. |
| `config:sensitive:set <path> <value>` | Marks config value as sensitive (e.g., passwords). |
| `config:sensitive:remove <path>` | Removes sensitive flag from a config. |

## EAV attributes

Magento stores product attributes in an Entity-Attribute-Value (EAV) model.

| Command | What it does |
| --- | --- |
| `eav:attribute:remove <attribute_code>` | Removes a custom attribute from the EAV model. |

## Inventory reservations

| Command | What it does |
| --- | --- |
| `inventory:reservation:list-inconsistencies` | Lists mismatches in stock reservations. |
| `inventory:reservation:create-compensations` | Fixes reservation issues by creating compensation records. |

## Logs

| Command | What it does |
| --- | --- |
| `dev:log:clean` | Clears system and exception logs. |

## Testing

| Command | What it does |
| --- | --- |
| `dev:tests:run {unit\|integration\|functional}` | Runs specified test suite. |

## Backup and restore

| Command | What it does |
| --- | --- |
| `setup:backup --code --media --db` | Creates backup of codebase, media, and DB. |
| `setup:rollback --code-file=<file> --db-file=<file>` | Restores from specified backup files. |

> [!WARNING]
> The `setup:backup` and `setup:rollback` commands are deprecated in current Magento releases. For a reliable, off-host copy of your store, use the platform [backups](../../platform/hosts/backups.md) instead.

## Cron and message-queue consumers

| Command | What it does |
| --- | --- |
| `cron:run` | Executes scheduled cron jobs immediately. |
| `cron:install` | Installs Magento cron jobs into system crontab. |
| `queue:consumers:list` | List the message-queue consumers |
| `queue:consumers:start <name>` | Start a single consumer |

TurboStack installs the Magento cron entries for your system user automatically. On a busy store, run each message-queue consumer as a persistent user service instead of relying on cron alone - see [Magento best practices](best-practices.md#message-queue-consumers).

> [!TIP]
> After deploying code on a production store, run the commands in this order: `setup:upgrade --keep-generated` -> `setup:di:compile` -> `setup:static-content:deploy` -> `cache:flush`.

> [!NOTE]
> The `n98-magerun2` tool is also installed on your host as `magerun2`. It adds convenience commands (for example `magerun2 sys:info`) on top of `bin/magento`. Run `magerun2 list` to see them.

> [!WARNING]
> `cache:flush`, `maintenance:enable` and `deploy:mode:set` change how the live storefront behaves. Run them during a quiet window and confirm the store still serves pages afterwards.

## Related

- [Magento reference](reference.md)
- [Deploy Magento on TurboStack](deploy.md)
- [Magento best practices](best-practices.md)
- [How to run multiple Magento store views](multiple-store-views.md)
- [Troubleshooting Magento](troubleshooting.md)
- [How to switch PHP version](../../technologies/php/switch-php-version.md)
- [Connect over SSH](../../platform/hosts/ssh.md)
