Magento CLI Commands List, Syntax, and Steps to Create Custom Commands
As a developer using Magento 2, you may have encountered the challenge of finding the right Magento CLI commands. It can be time-consuming and frustrating to search for the right commands on various websites when there is no centralized resource that provides a comprehensive Magento 2 command list.
If you’ve also been through the same situation, you’re not alone! As you may already know, Magento 2 Command-Line Interface (CLI) offers a convenient and efficient way to execute various tasks, including installing the platform, managing modules, themes, extensions, and configuring the store.
By utilizing the CLI commands, you can save time and effort while also enhancing your Magento 2 development experience. In this blog post, we’ll provide you with a comprehensive list of Magento 2 CLI commands that you can use as a reference whenever you need them. Moreover, we’ll also guide you on how to add your custom CLI commands in Magento 2. So, let’s dive into it and streamline your Magento 2 development workflow!
Table of Contents
- What is Magento 2 CLI
- Prerequisites For CLI (Command Line Interface) in Magento 2
- How to Access Files Through Magento CLI
- List of Useful Magento 2 Commands
- Fix Magento 2 Commands Not Working
- How to Add Custom Magento 2 CLI Commands
What Is Magento 2 CLI
A command line interface (CLI) is a text-based user interface (UI). Just like how driving a car requires you to interact with various controls, such as the steering wheel, pedals, and dashboard, the Magento 2 CLI allows you to interact with your computer or application using text-based commands.
For example, you can use the CLI to run programs, manage computer files, and configure settings, just like how you can use the controls of a car to navigate the road, accelerate or brake, and adjust the car’s settings.
Magento 2 has one command-line interface that performs installation and configuration tasks, including caching, installing, and more.
One specific example of using the Magento 2 CLI is clearing the cache. This is similar to how a driver may need
to clear the windshield of a car to remove any dirt or debris that may be obstructing their view. By using the
cache:clean command, you can remove any cached data that may be obstructing your view of your Magento 2
site, allowing you to see any changes you’ve made immediately.
Prerequisites for CLI (Command Line Interface) in Magento 2
Before you begin using the CLI, make sure that:
- Your system meets the requirements discussed in the System Requirements in the Installation guide.
- You have fulfilled all the requirements mentioned in the Installation guide’s Prerequisites section.
- After logging in to the Adobe Commerce server, you’ve switched to a user with permission to write to the Commerce file system. You can learn how to do this in the Installation guide’s File ownership and permissions section.
How to Access Files Through Magento CLI
To access the Magento 2 Command-Line Interface (CLI), you need to have SSH (Secure Shell) access to your server.
Note: Once you have SSH access, you can log in to your server using a terminal emulator such as PuTTY (for Windows) or Terminal (for macOS and Linux).
Step 1: SSH into the Server
Connect to your server via SSH using your preferred terminal tool and the appropriate user (typically the web server user or a user with permissions to the Magento file system).
Step 2: Navigate to the Magento Public (Root) Directory
The Magento CLI (bin/magento) is located in the Magento installation root directory. In most setups,
this is also the “public” web root (or contains the pub/ directory used as the docroot in the web server
configuration).
Use cd to navigate to your Magento root, for example:
cd /var/www/magento2
Or, depending on your OS and setup:
- Ubuntu example:
cd /var/www/magento2 - CentOS example:
cd /var/www/html/magento2
Once you are in the Magento root, you will see the bin/magento file. All CLI commands will be executed
from this directory.
Step 3: Go into the bin Directory (Optional)
You can either run commands from the root using bin/magento, or explicitly move into the bin
directory:
cd /var/www/magento2/bin
In that case, you can call commands as php magento or ./magento. Both approaches are valid, just be
consistent in your usage.
Magento CLI Entry Point
Now, you are in the public/root directory of the Magento 2 application and can run any bin/magento command.
The Magento CLI is located in the /bin/ directory of every Magento installation. You can access it from the
Magento root directory using the following command:
php bin/magento
Note: Using php before bin/magento is optional in the latest versions of Magento 2 if
the file is executable and your environment is configured correctly. Your operating system may automatically
find the global PHP binary to execute the command even if you leave it out.
Run Magento 2 CLI Command
To run any command, first access the server’s command line interface (CLI), and then navigate to the public directory (Magento root) of the Magento 2 application as shown above.
To run a specific Magento 2 CLI command, use the following pattern:
bin/magento [command-name] [arguments]
Replace:
[command-name]with the name of the Magento 2 CLI command.[arguments]with any required or optional arguments for the command.
For example, to flush the Magento 2 cache, run:
bin/magento cache:flush
Magento 2 CLI Command Structure
The Magento 2 CLI commands use the following basic structure:
bin/magento [option] [arguments]
In this structure:
bin/magentois the path to the Magento 2 CLI executable file.[option]is the name of the CLI command you want to run.[arguments]are the optional parameters you can pass to the command.
List All Commands
First, to check the list of all available commands in Magento 2, run the command below:
bin/magento list
You can call bin/magento CLI commands using shortcuts instead of the full command name. For example, you can call
bin/magento setup:upgrade using bin/magento s:up or bin/magento s:upg. Magento supports a flexible
shortcut syntax for many commands.
Below are some of the most useful and common Magento commands for managing the Magento application.
Magento 2 Cache Commands
Command: bin/magento cache:{enable|disable|clean|flush|status}
bin/magento cache:status
Description: List cache types and their status.
bin/magento cache:enable
Description: Enable all caches or a specific cache type.
bin/magento cache:disable
Description: Disable all caches or a specific cache type.
bin/magento cache:clean
Description: Deletes cache entries generated by Magento only.
bin/magento cache:flush
Description: Deletes all cache of the same storage (including non-Magento cache in the same backend).
Magento 2 Indexer Commands
The indexer is widely used in Magento 2. Previously there wasn’t any method to update indexing manually, but now it can also be done through the Magento Admin panel or via CLI. Besides reindexing using the Magento reindex command, you have the option to set indexing mode and check the status of the indexer via Magento CLI.
Command: bin/magento indexer:{status|show-mode|set-mode|reindex|info|reset|show-dimensions-mode|set-dimensions-mode}
bin/magento indexer:info
Description: Show list of all indexers.
bin/magento indexer:status
Description: View status of all indexers or specific indexers.
bin/magento indexer:set-mode
Description: Set indexer mode (e.g., realtime or schedule) for all or specific indexers.
bin/magento indexer:reindex
Description: Reindex all indexers or a specific indexer.
bin/magento indexer:show-mode
Description: View current mode configuration of all indexers.
Magento 2 Admin Commands
With Magento 2 Admin commands, you can create a new admin user, unlock a user, or work with Adobe IMS modules directly via CLI.
Command: bin/magento admin:user:{create|unlock}
bin/magento admin:user:create [--=<value>, …]
Description: Create an Administrator user.
bin/magento admin:user:unlock
Description: Unlock an Admin account.
bin/magento admin:adobe-ims:status
Description: Status of Adobe IMS module.
bin/magento admin:adobe-ims:info
Description: Show Adobe IMS module configuration information.
bin/magento admin:adobe-ims:enable
Description: Enable Adobe IMS module.
bin/magento admin:adobe-ims:disable
Description: Disable Adobe IMS module.
Magento 2 Module Commands
These commands can be used to enable, disable, uninstall, or check the status of installed modules through the Magento CLI. Disabling or uninstalling a module will fail if there is any dependency on that module.
Command: bin/magento module:{status|enable|disable|uninstall}
bin/magento module:status
Description: Check the status of Magento modules.
bin/magento module:enable Vendor_Module
Description: Enable a specific Magento module.
bin/magento module:disable Vendor_Module
Description: Disable a specific Magento module.
bin/magento module:uninstall Vendor_Module
Description: Uninstall a specific Magento module.
Magento 2 Cron Commands
These commands execute or manage scheduled Magento Cron jobs. You can put these commands in your system scheduler (crontab) so that application tasks can be executed in a timely manner.
Command: bin/magento cron:{install|remove|run}
bin/magento cron:install
Description: Generates and installs crontab for the current user.
bin/magento cron:remove
Description: Removes Magento tasks from crontab.
bin/magento cron:run
Description: Runs jobs according to schedule configuration.
Magento 2 Maintenance Commands
Magento maintenance commands help you keep your website running smoothly by enabling or disabling maintenance mode and configuring allowed IPs.
Command: bin/magento maintenance:{status|enable|disable|allow-ips}
bin/magento maintenance:allow-ips 127.0.0.1
Description: Set maintenance mode exempt IPs.
bin/magento maintenance:disable
Description: Disable maintenance mode.
bin/magento maintenance:enable
Description: Enable maintenance mode.
bin/magento maintenance:status
Description: Display maintenance mode status.
Magento 2 Info Commands
By using Magento 2 info commands, users can gain insights and access information about their website and the system running it.
Command: bin/magento info:{adminuri|backups:list|currency:list|dependencies:*|language:list|timezone:list}
bin/magento info:adminuri
Description: Displays the Magento Admin URI.
bin/magento info:backups:list
Description: Prints list of available backup files.
bin/magento info:currency:list
Description: Displays the list of available currencies.
bin/magento info:dependencies:show-framework
Description: Shows number of dependencies on Magento framework.
bin/magento info:dependencies:show-modules
Description: Shows number of dependencies between modules.
bin/magento info:dependencies:show-modules-circular
Description: Shows number of circular dependencies between modules.
bin/magento info:language:list
Description: Displays the list of available language locales.
bin/magento info:timezone:list
Description: Displays the list of available timezones.
Magento 2 Setup Commands
There are many things you can do with Magento setup commands, including installation, upgrades, configuration, and static content deployment.
bin/magento setup:config:set
Description: Creates or modifies the deployment configuration.
bin/magento setup:di:compile
Description: Generates DI configuration and all missing classes that can be auto-generated.
bin/magento setup:upgrade
Description: Upgrades the Magento application, database data, and schema.
bin/magento setup:uninstall
Description: Uninstalls the Magento application.
bin/magento setup:install
Description: Installs the Magento application.
bin/magento setup:static-content:deploy
Description: Deploys static view files.
Magento 2 offers a collection of CLI commands to facilitate the deployment of a store’s static content. This encompasses CSS, JavaScript, HTML files, images, fonts, and various media assets. These commands are also leveraged when performing version upgrades or implementing security patches in Magento 2.
bin/magento deploy:mode:set developer
Description: Set application mode (e.g., developer, production).
bin/magento deploy:mode:show
Description: Displays the current application mode.