Blog

How to use Magento 2 Command line Interface

How to use Magento 2 Command line Interface?

The Magento 2 Command line Interface or CLI is a feature that can be used for different types of installation and configuration functions. While this Command line Interface comes with an easily navigable and user friendly interface, it is necessary for a user to learn about its features and functions so that one can benefit from it. Professional ecommerce development firms like Sakshi consider it important for a developer to learn about the Magento 2 Command line Interface for ease of use during the developmental phase.

With the following command, the Magento 2 Command line Interface can be easily installed:

/bin/magento

Here are some of the functions that can be performed with the help of the Magento 2 Command line Interface program.

  • Installing Magento as well as all related tasks like updating or creating the database schema, developing the deployment configuration, etc.
  • Creating translation packages and translation dictionaries
  • Managing the indexes, including reindexing
  • Clearing the cache
  • Creating the missing classes like interceptors and factories for plug-ins; also producing dependency
    injection configuration suited for object manager.
  • Creating the CSS from LESS
  • Deploying the static view files

There are also a range of other benefits that can be obtained from using the Magento 2 Command line Interface:

  • A particular command can list all the existing commands for installation and configuration. This command goes as (php /bin/magento list).
  • It has a steady user interface that is based on Symfony
  • CLI is easily extensible which means that it can be easily plugged into by the third party developers. It also provides with the additional advantage of eliminating the users’ learning curve.
  • Commands for the disabled modules are not displayed with the Magento 2 Command line Interface.

Steps for configuring Magento

Firstly, you need to log in to Magento server as admin or enter as a user with consents for writing on Magento file system. A good way to accomplish this is to login as Magento file system owner.

If you are using bash shell, the following syntax will help you to switch to Magento file system owner as well as enter the command simultaneously.

su <Magento file system owner> -s /bin/bash -c <command>

On the other hand, if Magento file system owner is not permitting logins, you can perform the following task:

sudo -u <Magento file system owner>  <command>

In order to run the Magento commands easily from any directory, you need to add <your Magento install dir>/bin to the system PATH.

Since shells often have differing syntax, it is always better consult references like unix.stackexchange.com.

Here is a bash shell example meant for CentOS:

export PATH=$PATH:/var/www/html/magento2/bin

Alternately, you can run the command in the following method:

cd <your Magento install dir>/bin and run them as ./magento <command name>

php <your Magento install dir>/bin/magento <command name>

Keep in mind that <your Magento install dir> is basically a subdirectory of the web server’s docroot.

  • For managing the cache – magento setup:cache:{enable|disable|clean|flush|status}
  • For creating a translation package or a translation dictionary – magento i18n:{collect-phrases|pack}
  • For managing the indexers – magento setup:indexer:{status|show-mode|set-mode|reindex|info}
  • For running automated tests – magento dev:tests:run

For more contact Webzguru.

How to create a successful logo for your brandsuccessful logo for your brandHow to embed images from Google Photos into your website

We have 15 years experience

reach experienced into web and mobile development, custom solutions for your business.