Useful Magento 2 Commands List

Useful Magento 2 Commands List

Magento 2 provides CLI (command line interface) that helps Magento 2 Developers perform a lot of tasks such as clean cache, install sample data,  reindex, generate code, create database backups, add new admin user and many more tasks. Magento 2 CLI commands is really useful to perform these kinds of tasks. As you know Magento 2 SSH Commands is one of the most important tool in a Magento 2 Developer. This blog post has Magento 2 Commands Cheat Sheet. I have compiled a list of most useful Magento 2 commands.

Before you begin

Before you start using these Magento 2 Commands you will need to have SSH access to your server where you have Magento 2 and incase your working on Magento 2 on your local machine you will have to have access the Command Line.

Below is the Magento 2 Commands list :

CommandDescription
php bin/magento listUse php bin/magento list command to display a complete list of Magento 2 commands
php bin/magento helpUse php bin/magento help <command>, example php bin/magento help setup:install
composer create-project –repository-url=https://repo.magento.com/ magento/project-community-edition magento241Use composer create-project –repository-url=https://repo.magento.com/ magento/project-community-edition magento241 command to create a new composer project using the Magento Open Source
php bin/magento setup:install –base-url=http://localhost/magento/magento241 –db-host=”localhost” –db-name=magento241 –db-user=root –db-password= –admin-firstname=”Sajan” –admin-lastname=”Kota” –admin-email=”sajan.kota@gmail.com” –admin-user=”sajan” –admin-password=”Pass123123123#” –language=en_US –currency=USD –timezone=America/Chicago –use-rewrites=1 –backend-frontname=”controlpanel” –search-engine=elasticsearch7 –elasticsearch-host=localhost –elasticsearch-port=9200Command to install Magento 2 Store
php bin/magento sampledata:installUse php bin/magento sampledata:install command to Install optional Magento sample data after you install the Magento application.
php bin/magento sampledata:removeUse php bin/magento sampledata:remove command to remove all sample data packages from composer.json
php bin/magento sampledata:resetUse php bin/magento sampledata:reset command to reset all the sample data modules for re-installation
php bin/magento config:setUse php bin/magento config:set command to sets any non-sensitive configuration value by its configuration path
php bin/magento config:sensitive:setUse php bin/magento config:sensitive:set command to set any sensitive configuration value by its configuration path
php bin/magento config:showUse php bin/magento config:show command to show saved configuration value for the given path, if the path is not specified , all the saved values will be shown.
php bin/magento setup:uninstall [–magento-init-params MAGENTO-INIT-PARAMS]Use php bin/magento setup:uninstall command to uninstalls the Magento application
php bin/magento setup:config:setUse php bin/magento setup:config:set command to provide information Magento needs to initialize and bootstrap.
php bin/magento setup:backup [options]Use php bin/magento setup:backup command to take backup of Magento 2 Application code base(–code), Media(–media) and database (–db).
php bin/magento setup:rollback [options]Use Rolls back Magento Application codebase, media and database
php bin/magento setup:db-data:upgradeUse php bin/magento setup:db-data:upgrade command to Installs and upgrades data in the DB.
php bin/magento setup:db-declaration:generate-patchUse php bin/magento setup:db-declaration:generate-patch command to generate patch and put it in specific folder.
php bin/magento setup:db-declaration:generate-whitelist Use php bin/magento setup:db-declaration:generate-whitelist command to generate whitelist of tables and columns that are allowed to be edited by declaration installer
php bin/magento setup:db-schema:add-slaveUse php bin/magento setup:db-schema:add-slave command to add a slave database
php bin/magento setup:db-schema:split-quoteUse php bin/magento setup:db-schema:split-quote command to move checkout quote related tables to a separate DB server
php bin/magento setup:db-schema:split-salesUse php bin/magento setup:db-schema:split-sales command to move sales related tables to a separate DB server
php bin/magento setup:db-schema:upgradeUse php bin/magento setup:db-schema:upgrade command to Install and upgrade the DB schema
php bin/magento setup:db:statusUse php bin/magento setup:db:status command to check if DB schema or data requires upgrade
php bin/magento cache:cleanUse php bin/magento cache:clean command it deletes all the enabled cache of magento2. Disabled caches are not affected with php bin/magento cache:clean
php bin/magento cache:flushUse php bin/magento cache:flush command to delete all the enabled caches of magento2. Whether its enabled or disabled, php bin/magento cache:flush command even deletes all the third party cache along with the magento cache.
php bin/magento cache:statusUse php bin/magento cache:status command to check status of cache type(s)
php bin/magento cache:enable [cache_type]Use php bin/magento cache:enable Command will enable all the Magento 2 Cache.
php bin/magento cache:disable [cache_type]Use php bin/magento cache:disable Command will disable all the Magento 2 Cache.
php bin/magento setup:static-content:deployUse php bin/magento setup:static-content:deploy Command to deploy static content
php bin/magento setup:static-content:deploy -fUse php bin/magento setup:static-content:deploy -f command to force deploy on 2.2.x or later
php bin/magento setup:static-content:deploy en_USUse php bin/magento setup:static-content:deploy en_US Command to deploy static content for particular language
php bin/magento setup:static-content:deploy –theme=”Magento/backend”Use php bin/magento setup:static-content:deploy –theme=”Magento/backend” command to deploy static content for specified theme
php bin/magento setup:static-content:deploy en_US –exclude-theme Magento/luma –no-html-minifyUse php bin/magento setup:static-content:deploy en_US –exclude-theme Magento/luma –no-html-minify command to exclude when deploying static content. 
php bin/magento catalog:images:resizeUse php bin/magento catalog:images:resize command to resize all images for display on your storefront.
php catalog:product:attributes:cleanupUse php catalog:product:attributes:cleanup command to remove unused product attributes.
php bin/magento indexer:reindexUse php bin/magento indexer:reindex
Command to reindex all or selected indexers one time only.
php bin/magento indexer:set-dimensions-modeUse php bin/magento indexer:set-dimensions-mode command to set Indexer Dimensions Mode.
php bin/magento indexer:show-dimensions-modeUse php bin/magento indexer:show-dimensions-mode command to show Indexer Dimension Mode
php bin/magento indexer:resetUse php bin/magento indexer:reset command to all index types
php bin/magento indexer:infoUse php bin/magento indexer:info to view a list of all indexers
php bin/magento indexer:statusUse php bin/magento indexer:status
command to view the status of all indexers or specific indexers.
php bin/magento indexer:show-modeUse php bin/magento indexer:show-mode
Command to view the current indexer configuration
php bin/magento indexer:set-mode {realtime|schedule} [indexer]Use php bin/magento indexer:set-mode command to specify the indexer configuration.
php bin/magento info:adminuriUse php bin/magento info:adminuri command to displays the magento Admin URI
php bin/magento info:backups:listUsee php bin/magento info:backups:list command to list of available backup files.
php bin/magento info:currency:listUse php bin/magento info:currency:list command to display the list of available currencies.
php bin/magento info:language:listUse php bin/magento info:language:list command to display the list of available language locales.
php bin/magento info:timezone:listUse php bin/magento info:timezone:list command to displays the list of available timezones
php bin/magento info:dependencies:show-frameworkUse php bin/magento info:dependencies:show-framework command to show number of dependencies on Magento framework
php bin/magento info:dependencies:show-modules Use php bin/magento info:dependencies:show-modules [-o|–output OUTPUT] command to show the total number of dependencies between modules and whether the dependencies are hard or soft.
php bin/magento info:dependencies:show-modules-circular Use php bin/magento info:dependencies:show-modules-circular command to show number of circular dependencies between modules.
php bin/magento store:listUse php bin/magento store:list command to display the list of stores in Magento 2 .
php bin/magento store:website:listUse php bin/magento store:website:list command to display the list of websites in Magento 2
php bin/magento theme:uninstall frontend/ExampleCorp/SampleModuleTheme Use php bin/magento theme:uninstall command to uninstall the theme in Magento 2
php bin/magento inventory:reservation:list-inconsistenciesUsing the php bin/magento inventory:reservation:list-inconsistencies command detects and lists all reservation inconsistencies. Use the command options to check only completed or incomplete orders, or all.
php bin/magento inventory:reservation:create-compensationsUse php bin/magento inventory:reservation:create-compensations command to create compensation reservations.
php bin/magento inventory-geonames:import …Using php bin/magento inventory-geonames:import command to download and import geo names
php bin/magento module:statusUse php bin/magento module:status Command to check the status of all the modules in Magento 2.
php bin/magento module:enable Namespace_ModuleUse php bin/magento module:enable Namespace_Module command to enable a specific module
php bin/magento module:disable Namespace_ModuleUse php bin/magento module:disable Namespace_Module command to disable a specific module
php bin/magento module:uninstall Namespace_ModuleUse php bin/magento module:uninstall Namespace_Module command to uninstall a specific module
php bin/magento deploy:mode:showUse php bin/magento deploy:mode:show
command to display the current Magento 2 mode
php bin/magento deploy:mode:set productionUse php bin/magento deploy:mode:set production
command to set the Magento 2 store to production mode
php bin/magento deploy:mode:set developerUse php bin/magento deploy:mode:set developer
command to set the Magento 2 store to developer mode
php bin/magento setup:di:compileUse php bin/magento setup:di:compile
command will compile the DI configuration and generate the code.
php bin/magento admin:user:create –admin-firstname=John –admin-lastname=Doe –admin-email=j.doe@example.com –admin-user=j.doe –admin-password=A0b9%t3gUse this command to create a new administrator or to edit an existing administrator.
php bin/magento admin:user:createIf you use php bin/magento admin:user:create command without specify any parameters. Magento will ask about the parameters in the CLI
php bin/magento admin:user:unlock adminusernameUse php bin/magento admin:user:unlock adminusername command to unlock Magento 2 admin user account
php bin/magento app:config:dump Use php bin/magento app:config:dump {config-types} to create the dump of magento 2 application. Available config types include scopes, system, themes, and i18n. In case no config types are specified, the command dumps all system configuration information.
php bin/magento app:config:importUse php bin/magento app:config:import command to Import data from shared configuration files to appropriate data storage
php bin/magento app:config:statusUse php bin/magento app:config:status command to check if config propagation requires update.
php bin/magento dev:profiler:enableUse php bin/magento dev:profiler:enable command to enable the profiler in Magento 2
php bin/magento dev:profiler:enable htmlTo enable the profiler using type html and create a flagfile:
php bin/magento dev:profiler:enable csvfileTo enable the profiler using type csvfile and create a flagfile:
php bin/magento dev:profiler:disableUse php bin/magento dev:profiler:disable command to disable the profiler in Magento 2
php bin/magento dev:template-hints:enableUse the php bin/magento dev:template-hints:enable command to enable template hints 
php bin/magento dev:template-hints:disableUse the php bin/magento dev:template-hints:disable command to disable template hints 
php bin/magento dev:template-hints:statusUse php bin/magento dev:template-hints:status command to show frontend template hints status
php bin/magento maintenance:enableUse php bin/magento maintenance:enable command to enable maintenance mode in Magento 2 Store.
php bin/magento maintenance:enable –ip=192.0.0.1 –ip=192.0.0.2Use php bin/magento maintenance:enable –ip=192.0.0.1 –ip=192.0.0.2
command to enable maintenance mode for all clients except 192.0.0.1 and 192.0.0.2:
php bin/magento maintenance:enable –ip=noneUse php bin/magento maintenance:enable –ip=none
command to clear the list of exempt IPs
php bin/magento maintenance:disableUse php bin/magento maintenance:disable command to disable maintenance mode in Magento 2 Store.
php bin/magento maintenance:disable –ip=noneUse php bin/magento maintenance:disable –ip=none command to remove list of exempt IP-addresses.
php bin/magento maintenance:disable –ip=192.0.0.1 –ip=192.0.0.2Use php bin/magento maintenance:disable –ip=192.0.0.1 –ip=192.0.0.2
command to disable maintenance mode for all clients except 192.0.0.1 and 192.0.0.2:
php bin/magento maintenance:statusUse php bin/magento maintenance:status command to find the status of Magento 2 Store mode.
php bin/magento maintenance:allow-ips –ip=192.0.0.1 –ip=192.0.0.2Use php bin/magento maintenance:allow-ips –ip=192.0.0.1 –ip=192.0.0.2 command to allow access to the frontend store from a specific IP address while Magento store is in maintenance mode, type the following command:
php bin/magento media-content:syncUse php bin/magento media-content:sync command to synchronize content with assets.
php bin/magento media-gallery:syncUse php bin/magento media-gallery:sync command to synchronize media storage and media assets in the database.
php bin/magento module:config:statusUse php bin/magento module:config:status command to check the modules configuration in the ‘app/etc/config.php’ file and reports if they are up to date or not
php bin/magento queue:consumers:listUse php bin/magento queue:consumers:list command to list of MessageQueue consumers.
php bin/magento queue:consumers:startUse php bin/magento queue:consumers:start command to start MessageQueue consumer
php bin/magento cron:install –forceUse php bin/magento cron:install command to create a crontab in magento 2 Use --force to rewrite an existing Magento crontab.
php bin/magento cron:runUse php bin/magento cron:run command to run Magento 2 cron jobs
php bin/magento cron:run –helpUse php bin/magento cron:run –help command lists all the options to run the php bin/magento cron:run.
php bin/magento cron:removeUse php bin/magento cron:remove
command to remove the Magento crontab
php bin/magento customer:hash:upgradeUse php bin/magento customer:hash:upgrade command upgrades a customer password hash to the latest hash algorithm.Upgrade
php bin/magento dev:di:infoUse php bin/magento dev:di:info command provides information on Dependency Injection configuration for the class.
php bin/magento dev:query-log:disableUse php bin/magento dev:query-log:disable command to disable DB query logging
php bin/magento dev:query-log:enableUse php bin/magento dev:query-log:enable command to enable
php bin/magento dev:source-theme:deploy –type=”less” –locale=”en_US” –area=”frontend” –theme=”VendorName/themeName” css/styles-lUse php bin/magento dev:source-theme:deploy command to create symlinks to LESS files.
php bin/magento dev:tests:runUse php bin/magento dev:tests:run command to run tests. Available types of test to run: all, unit, integration, integration-all, static, static-all, integrity, legacy, default.
php bin/magento downloadable:domains:add www.example.comUse php bin/magento downloadable:domains:add www.example.com command to add to add a domain to downloadable_domains.
php bin/magento downloadable:domains:remove www.example.comUse php bin/magento downloadable:domains:remove command to remove a domain to downloadable_domains.
php bin/magento downloadable:domains:showUse php bin/magento downloadable:domains:show command to display downloadable domains whitelist
php bin/magento i18n:collect-phrases [-o|–output=””] [-m|–magento]Use php bin/magento i18n:collect-phrases command to create .csv file
php bin/magento i18n:pack [-m|–mode MODE] [-d|–allow-duplicates] [–]Use php bin/magento i18n:pack command to save language package
php bin/magento i18n:uninstall [-b|–backup-code] {language package name} … {language package name}Use php bin/magento i18n:uninstall command to Uninstall language packages
php bin/magento setup:performance:generate-fixturesUse php bin/magento setup:performance:generate-fixtures command to generates fixtures.
php bin/magento setup:store-config:setUse php bin/magento setup:store-config:set command to install the store configuration. Deprecated since 2.2.0. Use config:set instead
php bin/magento setup:upgradeUse php bin/magento setup:upgrade command to upgrade the Magento database schema and data.

The optional –keep-generated option should be used only in limited circumstances by experienced system integrators. magento setup:upgrade –keep-generated should never be used in a development environment.
php bin/magento support:backup:codeUse php bin/magento support:backup:code command to create create code backup.
php bin/magento support:backup:dbUse php bin/magento support:backup:db command to create backs up the Magento database and compresses it in tar.gz format.
php bin/magento support:utility:checkUse php bin/magento support:utility:check command to check for required backup utilities.
php bin/magento support:utility:pathsUse php bin/magento support:utility:paths command to create utilities paths list
php bin/magento varnish:vcl:generateUse php bin/magento varnish:vcl:generate command to generates Varnish VCL and echos it to the command line
php bin/magento security:recaptcha:disable-for-user-forgot-passwordUse php bin/magento security:recaptcha:disable-for-user-forgot-password command to disable reCAPTCHA for admin user forgot password form.
php bin/magento security:recaptcha:disable-for-user-loginUse php bin/magento security:recaptcha:disable-for-user-login command to disable reCAPTCHA for admin user login form

I hope this blog post helped you find the Magento 2 Commands which you were looking for. 

This is the comprehensive list of all important and useful cli commands for Magento 2. For official reference of Magento 2 commands available through the bin/magento command-line tool. If you find that any of the Magento 2 commands are missing, then do let us know in the comments below. Also, please share this with us.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top