Home / Blog / Magento CLI course for free!
Magento CLI course for free!

Magento CLI course for free!

  • Anna KoshevaAnna Kosheva
  • April 20, 2022

    April 20, 2022

As you know, Magento 2 Open Source is a modern PHP-based eсommerce framework. 

And as with every framework, it provides a command-line interface for performing different operations with the system.

It includes 

  • the installation of a website
  • enabling additional plugins
  • modifying data
  • performing maintenance activities such as caching security performance-related commands
  • and much more…

Magento 2 Open Source includes a so-called Magento CLI that stands for Magento Command Line Interface that ships together with Magento 2 Open Source.

Following is a summary of the process

  1. Create a Command class (the recommended location is <your component root dir>/Console/Command). See <Magento_Store_module_dir>/Console/Command/StoreListCommand.php for example.
    namespace Magento\CommandExample\Console\Command;
    use Symfony\Component\Console\Command\Command;
    use Symfony\Component\Console\Input\InputInterface;
    use Symfony\Component\Console\Input\InputOption;
    use Symfony\Component\Console\Output\OutputInterface;

     * Class SomeCommand
    class SomeCommand extends Command
        private const NAME = 'name';

         * @inheritDoc
        protected function configure()
            $this->setDescription('This is my first console command.');


         * Execute the command
         * @param InputInterface $input
         * @param OutputInterface $output
         * @return null|int
        protected function execute(InputInterface $input, OutputInterface $output)
            if ($name = $input->getOption(self::NAME)) {
                $output->writeln('<info>Provided name is `' . $name . '`</info>');

            $output->writeln('<info>Success Message.</info>');
            $output->writeln('<error>An error encountered.</error>');
            $output->writeln('<comment>Some Comment.</comment>');

2. Declare your Command class in Magento\Framework\Console\CommandListInterface and configure the command name using dependency injection (<your component root dir>/etc/di.xml):

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="Magento\Framework\Console\CommandListInterface">
            <argument name="commands" xsi:type="array">
                <item name="commandexample_somecommand" xsi:type="object">Magento\CommandExample\Console\Command\SomeCommand</item>

3. Clean the cache:

$ bin/magento cache:clean

4. Regenerate the code:

$ bin/magento setup:di:compile

As a result, the new command my:first:command that accepts a –name parameter is ready to use.

$ bin/magento my:first:command –name ‘John’

Congratulations! You’re the winner!

But there are other tasks for CLI. Also you should know about:

  • Changing Magento 2 CLI File Permissions
  • The CLI commands difference between installed and non-installed Magento 2
  • The Admin User Create command
  • The Admin URI Command
  • The Admin User Unlock Command
  • The deploy:mode:show Command

Good news! You can learn it for free!

Mage Mastery has a free course: Magento 2 Command Line Interface (CLI) for Beginners. 

What about conditions?

Absolutely Free

The course materials are absolutely free and you have 24/7 access to watch videos on your own pace.

Knowledge Gain

Each lesson content has been carefully polished and recorded so you can get most out with Mage Mastery

Join now!

  • Anna KoshevaAnna Kosheva
  • April 20, 2022

    April 20, 2022

Sign up and don't miss our awesome Mage Mastery lessons and updates!

Related Posts

Magento 2 Quick Start: Installation using Composer

The tutorial is for those who are looking to get a experience on how to install Magento 2 Open Source on a local development environment. A step-by-step video guide for developers.

CMS Block and Page in Magento 2

In this tutorial we will reveal the difference between CMS Page and Block in Magento 2.

How to Configure Varnish 6 and nginx with ssl for Magento 2

In this tutorial, we are going to set up and configure Varnish Cache with nginx and SSL (https) certificate for a Magento 2 Open Source.
If you like this blog post, you may want to watch
Start: March 28, 2021
Max Pronko
Web Icon20 lessons
Clock Icon15 hours
Adobe Certified Professional — Magento Commerce Developer Study Group is an 10-week (1.5 hours/week) instructor-led study group. This study group will help PHP and JavaScript developers evaluate their readiness and prepare for the Adobe Certified Professional — Magento Commerce Developer exam.
Start: March 15, 2021
Max Pronko
Web Icon80 lessons
Clock Icon15 hours
Magento 2 Development Workshop is for those who want to practice and learn how to implement Magento 2 extensions. During the workshop, you will have lots of homework, practical exercises, video lessons, and theory that will give you the required skills for your Magento 2 job.
2022 © Made with ❤ by Max Pronko