Adobe deprecated the Web Setup Wizard in Magento variations 2.3.6 and above. So if you wish to carry out jobs like setting up a Magento 2 style or extension, you’ll require to utilize the Magento 2 command line user interface (CLI).
In this guide, we’ll describe the essentials of the Magento CLI and reveal you how to utilize it for day-to-day jobs like handling your shop cache and indexing.
Here’s what we’ll cover:
An Intro to the Magento CLI
The Magento CLI is an open source tool that assists you handle the Magento application and its modules from the command line. You can do whatever from setting up Magento 2 to setting up and updating the application utilizing the Magento CLI.
The Magento CLI lies in the << project-root>>/ bin/ directory site of every Magento setup. You can access it from the Magento root directory site utilizing the following command:
$ php bin/magento
Note: Utilizing “php” prior to bin/magento is optional. Your os will instantly discover the international PHP variable to perform the command even if you leave it out.
The above command will output the Magento CLI assist page to your terminal screen. You’ll see a list of all offered commands and a quick description of every one as follows:
The Magento CLI Command Calling Convention Explained
Magento CLI commands utilize the following syntax:
$ command [options] [arguments]
For instance, here’s a command you’ll utilize to release fixed material in Magento 2:
$ php bin/magento setup: static-content: release
In the above example, “setup: static-content: release” is the command name in the “group: [subject:] action” format.
The “group” is a set of associated commands classified based upon a domain or workflow. One command group can have numerous topics distinct to its domain, and each topic can have numerous actions.
For example, here are 2 various actions you can carry out utilizing the setup: config group and topic:
$ bin/magento setup: config: set.
$ bin/magento setup: config: erase
Defining an action in the command name is optional. You can perform some commands without an action, such as:
$ bin/magento setup: set up
Magento CLI commands carry out exact actions associated with the setup and management of a Magento shop. However you can customize their habits utilizing alternatives and arguments.
For instance, here’s a Magento 2 CLI command with a choice and argument:
$ bin/magento module: disable– force Magento_Catalog
Here, “module: disable” is the command name, “– force” is the choice, and “Magento_Catalog” is the argument specifying the module you wish to disable.
10 Standard Jobs You Can Carry Out Utilizing the Magento CLI
Here’s a fast rundown of 10 jobs you can perform with the Magento CLI.
Note: All commands showed listed below need to be run by the Magento file system owner.
1. Set Up Magento 2
You can set up the core Magento application utilizing the setup: set up command. For instance:
$ bin/magento setup: set up.
— base-url= https://example.com.
— db-host= localhost.
— db-name= magento.
— db-user= magento_user.
— db-password=” ****************”
— admin-firstname= bob.
— admin-lastname= smith.
— admin-user= bob.
— admin-password= *********.
— language= en_US.
— currency= USD.
— timezone= America/Chicago.
— use-rewrites= 1
2. Set Up Magento 2 Cron
Magento 2 cron is vital for automatic jobs like upgrading indexes on a schedule and sending order e-mails. You can produce and set up cron for Magento 2 utilizing the following command:
$ bin/magento cron: set up
And if you want to run cron tasks by hand, you can do that by carrying out:
$ bin/magento cron: run
3. Handle Magento 2 Indexers
Magento utilizes indexing to upgrade shop information such as stock details, item prices, and client information to match the information kept in the database.
You can see all indexers on your shop utilizing the following command:
$ bin/magento indexer: details
Similarly, you can set the indexer mode type to “realtime” or “schedule” utilizing:
$ bin/magento indexer: set-mode schedule [index-name]
You can likewise by hand reindex the indexers utilizing:
$ bin/magento indexer: reindex
4. Set Up Magento 2 Security Functions
Magento 2 consists of a number of default security functions, such as reCAPTCHA and Two-factor authentication. You can handle those functions utilizing the Magento CLI security group of commands.
For instance, you can disable reCAPTCHA for admin users utilizing the following command:
$ bin/magento security: recaptcha: disable-for-user-login
And you can reset Two-factor authentication for an admin user utilizing:
$ bin/magento security: tfa: reset << username> <> < provider-code>>
5. Deploy Static View Files
Magento produces fixed view files such as CSS and obstruct HTML files and serves them from the cache in a production environment to enhance shop efficiency.
Here’s how you can release fixed view files in Magento 2 from the CLI:
$ bin/magento setup: static-content: release
Additionally, you can customize the command to leave out particular styles and release fixed material for a particular shop consider as follows:
$ bin/magento setup: static-content: release en_US– exclude-theme Magento/luma
6. Handle the Magento Operation Mode
You can run the Magento application in 4 various modes. For example, if you’re checking code, you can run it in designer mode. And if you’re running a live shop, you can run it in production mode for much better efficiency and security.
Here’s how you can set the Magento operation mode to production from the CLI:
$ bin/magento deploy: mode: set production
7. Set Up Upkeep Mode
The Magento 2 upkeep mode disables access to the frontend throughout regular upkeep jobs like style and design updates. Here’s how you can allow upkeep mode in Magento 2 from the CLI:
$ bin/magento upkeep: allow
Additionally, you can excuse 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 architecture enables merchants to tailor their shop style and performance utilizing third-party modules. It’s not a surprise that information from BuiltWith reveals that 8% of the leading 10,000 sites utilize Magento to power their online shop.
Adobe offers numerous module management commands organized into the module: classification. For example, here’s how you can inspect the status of all made it possible for modules on your shop:
$ bin/magento module: status– made it possible for
9. Handle the Magento 2 Cache
Magento’s cache management system offers a simple method to enhance Magento shop efficiency. Magento utilizes various cache types such as design, complete page, and obstruct HTML output.
You can see their status utilizing the following command:
$ bin/magento cache: status
And to clear the Magento cache, you can utilize the following command:
$ bin/magento cache: tidy
10. Produce New Admin Users
The Magento CLI lets you produce brand-new admin users without visiting to the admin panel. Here’s how you can include a brand-new admin user from the CLI:
$ bin/magento admin: user: produce.
— admin-user ADMIN-USER.
— admin-password ADMIN-PASSWORD.
— admin-email ADMIN-EMAIL.
— admin-firstname ADMIN-FIRSTNAME.
— admin-lastname ADMIN-LASTNAME
How To Include a Custom-made Magento 2 CLI Command
Like all things Magento, the Magento CLI is extensible too. Here’s how you can include a custom-made command to the Magento CLI in 5 basic actions.
Note: All actions showed listed below need to be carried out by the Magento filesystem owner.
Action 1: Produce a Standard Magento Module
Log in to your server over SSH and produce a custom-made Magento 2 module with a module.xml and a registration.php file.
Action 2: Produce a di.xml File
Produce a di.xml file in the and so on/ folder of your module and paste the following code inside it: