A Newbie’s Information to the Magento CLI [2022]

Adobe deprecated the Net Setup Wizard in Magento variations 2.3.6 and above. So if you wish to carry out duties like putting in a Magento 2 theme or extension, you’ll want to make use of the Magento 2 command line interface (CLI).

On this information, we’ll clarify the fundamentals of the Magento CLI and present you learn how to use it for each day duties like managing your retailer cache and indexing.

Right here’s what we’ll cowl:

An Introduction to the Magento CLI

The Magento CLI is an open supply software that helps you handle the Magento software and its modules from the command line. You are able to do the whole lot from putting in Magento 2 to configuring and upgrading the applying utilizing the Magento CLI.

The Magento CLI is positioned within the <project-root>/bin/ listing of each Magento set up. You’ll be able to entry it from the Magento root listing utilizing the next command:

$ php bin/magento

Word: Utilizing “php” earlier than bin/magento is non-obligatory. Your working system will routinely discover the worldwide PHP variable to execute the command even for those who go away it out.

The above command will output the Magento CLI assist web page to your terminal display screen. You’ll see an inventory of all accessible instructions and a short description of every one as follows:

The Magento CLI Command Naming Conference Defined

Magento CLI instructions use the next syntax:

$ command [options] [arguments]

For instance, right here’s a command you’ll use to deploy static content material in Magento 2:

$ php bin/magento setup:static-content:deploy

Within the above instance, “setup:static-content:deploy” is the command title within the “group:[subject:]motion” format.

The “group” is a set of associated instructions categorized primarily based on a website or workflow. One command group can have a number of topics distinctive to its area, and every topic can have a number of actions.

As an illustration, listed below are two totally different actions you may carry out utilizing the setup:config group and topic:

$ bin/magento setup:config:set

$ bin/magento setup:config:delete

Specifying an motion within the command title is non-obligatory. You’ll be able to execute some instructions with out an motion, comparable to:

$ bin/magento setup:set up

Magento CLI instructions carry out exact actions associated to the configuration and administration of a Magento retailer. However you may modify their habits utilizing choices and arguments.

For instance, right here’s a Magento 2 CLI command with an possibility and argument:

$ bin/magento module:disable --force Magento_Catalog

Right here, “module:disable” is the command title, “–force” is the choice, and “Magento_Catalog” is the argument defining the module you need to disable.

10 Fundamental Duties You Can Carry out Utilizing the Magento CLI

Right here’s a fast rundown of 10 duties you may execute with the Magento CLI.

Word: All instructions demonstrated under should be run by the Magento file system proprietor.

1. Set up Magento 2

You’ll be able to set up the core Magento software utilizing the setup:set up command. For instance:

$ bin/magento setup:set up 








--admin-email=electronic mail@instance.com 







2. Configure Magento 2 Cron

Magento 2 cron is important for automated duties like updating indexes on a schedule and sending out order emails. You’ll be able to generate and set up cron for Magento 2 utilizing the next command:

$ bin/magento cron:set up

And for those who’d wish to run cron jobs manually, you are able to do that by executing:

$ bin/magento cron:run

3. Handle Magento 2 Indexers

Magento makes use of indexing to replace storefront knowledge comparable to inventory info, product pricing, and buyer particulars to match the information saved within the database.

You’ll be able to view all indexers in your retailer utilizing the next command:

$ bin/magento indexer:data

Likewise, you may set the indexer mode sort to “realtime” or “schedule” utilizing:

$ bin/magento indexer:set-mode schedule [index-name]

You too can manually reindex the indexers utilizing:

$ bin/magento indexer:reindex

4. Configure Magento 2 Safety Options

Magento 2 contains a number of default security measures, comparable to reCAPTCHA and Two-factor authentication. You’ll be able to handle these options utilizing the Magento CLI safety group of instructions.

For instance, you may disable reCAPTCHA for admin customers utilizing the next command:

$ bin/magento safety:recaptcha:disable-for-user-login

And you may reset Two-factor authentication for an admin person utilizing:

$ bin/magento safety:tfa:reset <username> <provider-code>

5. Deploy Static View Information

Magento generates static view recordsdata comparable to CSS and block HTML recordsdata and serves them from the cache in a manufacturing setting to enhance retailer efficiency.

Right here’s how one can deploy static view recordsdata in Magento 2 from the CLI:

$ bin/magento setup:static-content:deploy

Optionally, you may modify the command to exclude sure themes and deploy static content material for a selected retailer view as follows:

$ bin/magento setup:static-content:deploy en_US --exclude-theme Magento/luma

6. Handle the Magento Operation Mode

You’ll be able to function the Magento software in 4 totally different modes. As an illustration, for those who’re testing code, you may run it in developer mode. And for those who’re working a dwell retailer, you may run it in manufacturing mode for higher efficiency and safety.

Right here’s how one can set the Magento operation mode to manufacturing from the CLI:

$ bin/magento deploy:mode:set manufacturing

7. Configure Upkeep Mode

The Magento 2 upkeep mode disables entry to the frontend throughout routine upkeep duties like design and format updates. Right here’s how one can allow upkeep mode in Magento 2 from the CLI:

$ bin/magento upkeep:allow

Optionally, you may exempt some IP addresses from the upkeep mode utilizing:

$ bin/magento upkeep:allow-ips <xxx.xxx.xxx.xxx>

8. Handle Magento 2 Modules and Extensions

Magento’s modular structure permits retailers to customise their retailer design and performance utilizing third-party modules. It’s no shock that knowledge from BuiltWith reveals that 8% of the highest 10,000 web sites use Magento to energy their on-line retailer.

Adobe offers numerous module administration instructions grouped into the module: class. As an illustration, right here’s how one can verify the standing of all enabled modules in your retailer:

$ bin/magento module:standing --enabled

9. Handle the Magento 2 Cache

Magento’s cache administration system offers a straightforward method to enhance Magento retailer efficiency. Magento makes use of totally different cache sorts comparable to format, full web page, and block HTML output.

You’ll be able to view their standing utilizing the next command:

$ bin/magento cache:standing

And to clear the Magento cache, you need to use the next command:

$ bin/magento cache:clear

10. Create New Admin Customers

The Magento CLI permits you to create new admin customers with out logging in to the admin panel. Right here’s how one can add a brand new admin person from the CLI:

$ bin/magento admin:person:create 

--admin-user ADMIN-USER 

--admin-password ADMIN-PASSWORD 

--admin-email ADMIN-EMAIL 

--admin-firstname ADMIN-FIRSTNAME 

--admin-lastname ADMIN-LASTNAME

How To Add a Customized Magento 2 CLI Command

Like all issues Magento, the Magento CLI is extensible as properly. Right here’s how one can add a customized command to the Magento CLI in 5 easy steps.

Word: All actions demonstrated under should be carried out by the Magento filesystem proprietor.

Step 1: Create a Fundamental Magento Module

Log in to your server over SSH and create a customized Magento 2 module with a module.xml and a registration.php file.

Step 2: Create a di.xml File

Create a di.xml file within the and many others/ folder of your module and paste the next code inside it:

<?xml model="1.0"?>

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/and many others/config.xsd">

<sort title="MagentoFrameworkConsoleCommandList">


<argument title="instructions" xsi:sort="array">

<merchandise title="CustomCommand" xsi:sort="object">NexcessCustomModuleConsoleCommandCustomCommand</merchandise>





Step 3: Create a Command Class

Create a command class file referred to as CustomCommand.php contained in the app/code/<vendor>/<module>/Console/Command listing of your customized module containing the next code:


namespace NexcessCustomModuleConsoleCommand;

use SymfonyComponentConsoleCommandCommand;

use SymfonyComponentConsoleInputInputInterface;

use SymfonyComponentConsoleOutputOutputInterface;

class CustomCommand extends Command


protected operate configure()



$this->setDescription('Customized command instance.');

father or mother::configure();


protected operate execute(InputInterface $enter, OutputInterface $output)


$output->writeln("Howdy World");



Step 4: Clear Magento Cache, Register the Module, and Recompile Code

Clear the cache, register your module, and regenerate Magento code utilizing the next instructions:

$ bin/magento cache:clear

$ bin/magento setup:improve

$ bin/magento setup:di:compile

Step 5: Check Your Customized Magento CLI Command

Your customized command is now prepared to make use of. Confirm it’s accessible by outputting the whole checklist of instructions to your terminal utilizing:

$ bin/magento checklist

Lastly, check the command utilizing:

$ bin/magento nexcess:helloworld

You need to see the next output:

Ultimate Ideas: A Newbie’s Information to the Magento CLI

The Magento CLI might sound intimidating at first. However when you perceive the way it works, you’ll understand that you just don’t must change into a developer to handle a Magento retailer, particularly for those who’re internet hosting your Magento retailer with managed Magento internet hosting by Nexcess.

Our internet hosting plans offer you entry to Magento-optimized servers with out coping with the technicalities of internet hosting Magento.

Browse our plans to get began right this moment.


Leave a Comment