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 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).
- Follow these steps to access and run Magento CLI:
- The general directory structure for Magento is as follows, which you can use to access your application from the server based on your operating system:
- cd /bin
- Example:
- Ubuntu: cd /var/www/magento2/bin
- CentOS: cd /var/www/html/magento2/bin
- Now, you are in the public 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. But this is only in the latest version of Magento 2 only. Your operating system will automatically find the global PHP variable 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 of the Magento 2 application. Here’s how:
Please add a step here on how to navigate to the public directory of the Magento 2 application.
To run a specific Magento 2 CLI command, run the following command:
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 the following command:
bin/magento cache:flush
List of Useful Magento 2 Commands and How to Use Them
The Magento 2 CLI commands can be accessed from the command line interface of your server or local environment. All Magento command-line interface (CLI) commands rely on the Magento application and must have access to its context, dependency injections, plug-ins, and so on.
Magento 2 CLI Command Structure:
Here is the basic structure of the Magento 2 CLI command:
bin/magento [option] [arguments]
In this command structure:
- bin/magento is the path to the Magento 2 CLI executable file.
is the name of the CLI command you want to run. - [] are the optional parameters you can pass to the command.
bin/magento list
List All Commands:
First, to check all the list of commands available 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, bin/magento s:upg. See shortcut syntax to understand how to use shortcuts with any CLI command. Here are some of the useful and common Magento commands for managing the Magento application:
Command: magento cache:{enable/disable/clean/flush/status}
bin/magento cache:status
Description:
To list cache types and their status
bin/magento cache:enable
Description:
To enable all caches OR any specific cache type
bin/magento cache:disable
Description:
To disable all caches OR any specific cache type
bin/magento cache:clean
Description:
It would delete cache types linked with Magento only
bin/magento cache:flush
Description:
Deletes all cache of the same storage
Magento 2 Indexer Commands
The indexer is a widely used option in Magento 2. Previously there wasn’t any method to update indexing manually, but now it can also be done through Magento’s Admin panel. Besides reindexing using the Magento reindex command, you have the option to set indexing mode and to 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}
EXAMPLE:
bin/magento indexer:info
Description:
Show list of all indexers
bin/magento indexer:status
Description:
View status of all indexers or specific indexer only
bin/magento indexer:set-mode
Description:
To reindex all the indexer or specific indexer only
bin/magento indexer:reindex
Description:
To invalidate all the indexer or specific indexer only
bin/magento indexer:show-mode
Description:
For viewing indexer current configuration
Magento 2 Admin Commands
With Magento 2 Admin Commands, you can create a new admin user, edit or unlock the user that is already created through Magento CLI.
Command:
- bin/magento admin:user:{create/unlock}
- bin/magento admin:user:create [–=, …]
Example:
bin/magento admin:user:create
Description:
Create an Administrator
bin/magento admin:user:unlock
Description:
Unlock Admin Account
bin/magento admin:adobe-ims:status
Description:
Status of Adobe IMS Module
bin/magento admin:adobe-ims:info
Description:
Information of Adobe IMS Module configuration
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
This Magento command can be used to enable, disable, uninstall or check the status of all the installed modules through Magento CLI. Disabling or uninstalling a module will fail with this Magento 2 command if there is any dependency on that module.
Command: bin/magento module:user:{status/enable/disable/uninstall}
Example:
bin/magento module:status
Description:
Check the status of Magento modules
bin/magento module:enable
Description:
To enable specific Magento module
bin/magento module:disable
Description:
To disable specific Magento module
bin/magento module:uninstall
Description:
To uninstall specific Magento module
Magento 2 Cron Command
This Magento 2 command can execute the scheduled Magento Cron jobs manually. You can put this command in the scheduler, so the application’s task can be executed in a timely manner. Speaking of Magento Cron jobs, you might be interested in our guide on how to create, set up, and configure Magento 2 Cron Job.
Command:
magento cron:run
Example:
bin/magento cron:install
Description:
Generates and installs crontab for current user
bin/magento cron:remove
Description:
Removes tasks from crontab
bin/magento cron:run
Description:
Runs jobs by schedule
Magento 2 Maintenance Commands
Magento Maintenance Commands can help you keep your website running smoothly. Here are some of the most useful maintenance commands.
Command: bin/magento maintenance:{status/enable/disable/allow-ips}
Here are some useful commands:
bin/magento maintenance:allow-ips
Description:
Sets maintenance mode exempt IPs
bin/magento maintenance:disable
Description:
Disables maintenance mode
bin/magento maintenance:enable
Description:
Enables maintenance mode
bin/magento maintenance:status
Description:
Displays maintenance mode status
Magento 2 Info Commands
By using Magento 2 info commands, users can gain insights to access information about their website and the system running it.
Command: bin/magento info:{adminuri/backups/currency/dependencies/language}
Here are some useful info commands:
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 a 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
here are plenty of things that you can do with Magento setup commands.
Here are some useful commands:
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, DB data, and schema
bin/magento setup:uninstall
Description:
Uninstalls the Magento application
bin/magento setup:install
Description:
Installs the Magento application
php 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.
Example:
bin/magento deploy:mode:set
Description:
Set application mode
bin/magento deploy:mode:show
Description:
Displays current application mode