![Useful Commands in Magento 2 - Kishan Savaliya](https://www.kishansavaliya.com/media/magefan_blog/xUseful-Commands-in-Magento-2-Kishan-Savaliya-image.png.pagespeed.ic.68mjaACarA.png)
Welcome to Kishan Savaliya's Magento 2 Blog. In this blog post, I will share Magento 2 commands list which will useful to you in your development.
If you're working with Magento, then you need to run various commands multiple times. Few command commands you can easily remember it. But, Magento having list of commands, that all commands you can use for various purpose, you can use that all commands instead of creating any custom scripts and it will save your time too.
I will provide you list of commands and describe usage of commands. If you're beginner then this post will be useful to you in your development, you can save this as your bookmark and you can easily find commands from here.
- Magento is using
Symfony\Component\Console\Command
component to implement command line features. - So you can use shortest unambiguous name instead of full name, e.g. s:up instead of setup:upgrade. You can learn more in the documentation of Symphony framework.
You can create your custom command as well in Magento, if you want to know how ? then you can check this post, I provided step by step tutorial for how to create custom console command in Magento 2? there.
Useful Magento 2 commands list with shortcut.
Go to your SSH/Terminal, and type below command there.
php bin/magento
This command will display list of all magento 2 commands, that is available in default Magento or if available in any custom module.
Now in that list, there's very first command which Displays help for a command. Below both commands return same output.
php bin/magento help
or
php bin/magento h
How to Create an admin user using CLI Command ?
php bin/magento admin:user:create --admin-user='admin' --admin-password='admin123' --admin-email='john.doe@example.com' --admin-firstname='John' --admin-lastname='Doe'
or
php bin/magento a:u:c --admin-user='admin' --admin-password='admin123' --admin-email='john.doe@example.com' --admin-firstname='John' --admin-lastname='Doe'
How to unlock Admin Account, if account locked after incorrect password attempts ?
php bin/magento admin:user:unlock admin_username
How to clean, flush, enable, disable cache type(s) and how to know cache type(s) status using command ?
- Clean Magento 2 cache
php bin/magento cache:clean
- Clean only specific cache type
php bin/magento cache:clean cache_type [config layout block_html full_page]
- Flush Magento 2 cache
php bin/magento cache:flush
- Flush only specific cache type
php bin/magento cache:flush cache_type [config layout block_html full_page]
- Disable Magento 2 cache
php bin/magento cache:disable
- Disable only specific cache type
php bin/magento cache:disable cache_type [config layout block_html full_page]
- Enable Magento 2 cache
php bin/magento cache:enable
- Enable only specific cache type
php bin/magento cache:enable cache_type [config layout block_html full_page]
- Check Status (Enable/Disable) of cache
php bin/magento cache:status
- Check status of only specific cache type
php bin/magento cache:status cache_type [config layout block_html full_page]
How to resize catalog images in Magento 2?
php bin/magento catalog:images:resize
How to remove unused product attributes in Magento 2?
php bin/magento catalog:product:attributes:cleanup
How to set System Configuration value using CLI in Magento 2 ?
php bin/magento config:set config_path value
For example, if we need to set Merge JS files option to Yes in production mode, and as we know in production mode, we can not able to see developer tab in system configuration, then we can set it's value using CLI command and we don't need to set developer mode for it.
php bin/magento config:set dev/js/merge_files 1
Using above command we can easily enable JS Merge option, you just need config path and it's appropriate value.
How to check system configuration value using CLI command in Magento 2 ?
php bin/magento config:show config_path
How to install cron using CLI commands in Magento 2 ?
php bin/magento cron:install
How to remove cron using CLI command in Magento 2 ?
php bin/magento cron:remove
How to run cron jobs by schedule in Magento 2?
php bin/magento cron:run
How to upgrade customer's password hash to the latest hash algorithm in Magento 2?
php bin/magento customer:hash:upgrade
How to check Magento 2 application mode using CLI command?
php bin/magento deploy:mode:show
How to set developer mode in Magento 2 using CLI command?
php bin/magento deploy:mode:set developer
How to set production mode in Magento 2 using CLI command?
php bin/magento deploy:mode:set production
You can set arguments --skip-compilation and it'll not compile and regenerate code.
How to enable template path hints using CLI command in Magento 2?
php bin/magento dev:template-hints:enable
After running above command you need to clear Magento cache.
How to disable template path hints using CLI command in Magento 2?
php bin/magento dev:template-hints:disable
After running above command you need to clear Magento cache.
How to Re-encrypt encrypted credit card data with latest encryption cipher?
php bin/magento encryption:payment-data:update
How to check allowed Indexers info in Magento 2 using CLI command ?
php bin/magento indexer:info
How to reindex data in Magento 2 using CLI command?
php bin/magento indexer:reindex
How to reset indexer status to invalidate in Magento 2 using CLI command?
php bin/magento indexer:reset
How to check status of Indexer in Magento 2 using CLI command?
php bin/magento indexer:status
How to show Index mode in Magento 2 using CLI command?
php bin/magento indexer:show-mode
How to set Index mode in Magento 2 using CLI command?
In Magento 2, we can set Update on Save and Update by Schedule index mode.
- Update on Save : realtime : Indexed data is updated as soon as any change made in backend.
- Update by Schedule : schedule : Data is indexed according to the schedule set by your Magento cron job.
php bin/magento indexer:set-mode {realtime|schedule} [indexer]
Here in above command,
- realtime - This will set selected indexer to update on save.
- schedule - This will set selected indexer to update by cron schedule.
- indexer - This is your list of indexer arguments, you can put multiple values here with space-seperated.
E.g.
php bin/magento indexer:set-mode schedule catalog_category_product catalog_product_category
How to check Magento 2 backend URI using CLI command?
php bin/magento info:adminuri
How to enable maintenance mode in Magento 2 using CLI command?
php bin/magento maintenance:enable
How to disable maintenance mode in Magento 2 using CLI command?
php bin/magento maintenance:disable
How to set exempt IP-addresses from maintenance list?
php bin/magento maintenance:allow-ips [list of ip addresses space-seperated]
How to check maintenance mode status in Magento 2? (Enable or Disable and List of exempt IP-addresses)
php bin/magento maintenance:status
How to check module's status using CLI command in Magento 2?
php bin/magento module:status Vendor_Module
How to enable new module in Magento 2 using CLI command?
php bin/magento module:enable Vendor_Module
How to disable any module in Magento 2 using CLI command?
php bin/magento module:disable Vendor_Module
How to uninstall module using CLI command installed by Composer in Magento 2?
php bin/magento module:uninstall Vendor_Module
How to install Magento 2 using CLI command?
You can check this blog post, I briefly explained there, how to install Magento 2 using Composer?
How to Takes backup of Magento Application code base, media and database using CLI command in Magento 2?
php bin/magento setup:backup
How to Upgrade Magento application, DB data and schema in Magento 2 using CLI command?
php bin/magento setup:upgrade
How to Upgrade Magento application without removing pub/static files using CLI command?
php bin/magento setup:upgrade --keep-generated
How to generate DI configuration classes and regenerate code in Magento 2 using CLI command?
php bin/magento setup:di:compile
How to deploy static view file in Magento 2 using CLI command?
php bin/magento setup:static-content:deploy [-f : force deployment in default and developer mode]
Deploy any specific language/locale static view files.
php bin/magento setup:static-content:deploy -f en_US en_GB
Deploy only specific themes
php bin/magento setup:static-content:deploy --theme Magento/luma --theme Magento/backend
How to check list of stores available in Magento 2 using CLI command?
php bin/magento store:list
Above command displays the list of stores, store code, name and status (enable/disable).
How to check list of websites available in Magento 2 using CLI command?
php bin/magento store:website:list
Above command displays the list of websites and website code.
Hope you may like this article and can understand this easily. You can add comments below in case if you have any questions regarding this article or if I missed anything here. I will check and get back to you with proper solution.
If you enjoyed this blog post, share it with friends!