136 Views

Comprehensive Guide to Magento 2 Useful Commands

As a Magento 2 developer, you’ll frequently use various CLI (Command Line Interface) commands to manage and maintain your projects. Having a consolidated list of these commands can significantly streamline your workflow. Below is a comprehensive list of the most crucial Magento 2 SSH/CLI commands you’ll often need.

1. Admin User Management

Create an Admin User

bash

Copy code

php bin/magento admin:user:create –admin-user=’admin’ –admin-password=’admin123′ –admin-email=’admin@yourwebsite.com’ –admin-firstname=’Johy’ –admin-lastname=’Roy’

Unlock Admin User Account

bash

Copy code

php bin/magento admin:user:unlock username

2. Setup and Installation

Setup Upgrades

bash

Copy code

php bin/magento setup:upgrade

Setup Upgrades without Removing pub/static Files

bash

Copy code

php bin/magento setup:upgrade –keep-generated

Uninstall Magento Application

bash

Copy code

php bin/magento setup:uninstall

3. Cache Management

Clean Cache

bash

Copy code

php bin/magento cache:clean

Clean Specific Cache Type

bash

Copy code

php bin/magento cache:clean cache_type

Disable Cache

bash

Copy code

php bin/magento cache:disable

Disable Specific Cache Type

bash

Copy code

php bin/magento cache:disable cache_type

Enable Cache

bash

Copy code

php bin/magento cache:enable

Enable Specific Cache Type

bash

Copy code

php bin/magento cache:enable cache_type

Flush Cache

bash

Copy code

php bin/magento cache:flush

Flush Specific Cache Type

bash

Copy code

php bin/magento cache:flush cache_type

Check Cache Status

bash

Copy code

php bin/magento cache:status

4. Static Content Deployment

Deploy Static Content

bash

Copy code

php bin/magento setup:static-content:deploy

Force Deploy (For Magento 2.2.x or later)

bash

Copy code

php bin/magento -f setup:static-content:deploy

Deploy for Specific Language

bash

Copy code

php bin/magento setup:static-content:deploy en_US

Deploy for Magento Backend Theme

bash

Copy code

php bin/magento setup:static-content:deploy –theme=”Magento/backend”

Deploy for Specific Themes

bash

Copy code

php bin/magento setup:static-content:deploy –theme Magento/luma –theme Magento/theme_number_two

Exclude Themes and No HTML Minification

bash

Copy code

php bin/magento setup:static-content:deploy en_US –exclude-theme Magento/luma –no-html-minify

5. Catalog Management

Resize Product Images

bash

Copy code

php bin/magento catalog:images:resize

Remove Unused Product Attributes

bash

Copy code

php bin/magento catalog:product:attributes:cleanup

6. Cron Jobs

Set Magento Crontab

bash

Copy code

php bin/magento cron:install –force

Run Scheduled Jobs

bash

Copy code

php bin/magento cron:run

Remove Magento Crontab

bash

Copy code

php bin/magento cron:remove

7. Index Management

Reindex

bash

Copy code

php bin/magento indexer:reindex

List Indexers

bash

Copy code

php bin/magento indexer:info

View Indexer Status

bash

Copy code

php bin/magento indexer:status

Show Indexer Mode

bash

Copy code

php bin/magento indexer:show-mode

Reset Indexer Status to Invalid

bash

Copy code

php bin/magento indexer:reset

Set Index Mode Type

bash

Copy code

php bin/magento indexer:set-mode {schedule|realtime} [indexer]

Example:

bash

Copy code

php bin/magento indexer:set-mode schedule catalog_category_product catalog_product_category

8. Internationalization

Collect All Phrases (4 Columns)

bash

Copy code

php bin/magento i18n:collect-phrases -o “\var\www\html\magento\app\design\i18n\xx_YY.csv” -m

Collect All Phrases (2 Columns)

bash

Copy code

php bin/magento i18n:collect-phrases -o “\var\www\html\magento\app\design\i18n\xx_YY.csv” \var\www\html\magento\app\design\frontend

Uninstall Language Packages

bash

Copy code

php bin/magento i18n:uninstall [-b|–backup-code] {language package name}

9. Deployment Modes

Set Developer Mode

bash

Copy code

php bin/magento deploy:mode:set developer

Set Production Mode

bash

Copy code

php bin/magento deploy:mode:set production

Check Current Mode

bash

Copy code

php bin/magento deploy:mode:show

10. Dependency Injection

Compile Dependency Injection

bash

Copy code

php bin/magento setup:di:compile

11. Module Management

See All Modules Status

bash

Copy code

php bin/magento module:status

Enable Module

bash

Copy code

php bin/magento module:enable VendorName_ModuleName

Disable Module

bash

Copy code

php bin/magento module:disable VendorName_ModuleName

Uninstall Module

bash

Copy code

php bin/magento module:uninstall VendorName_ModuleName

12. Backup Management

Print List of Available Backup Files

bash

Copy code

php bin/magento info:backups:list

13. Information Retrieval

List of Available Currencies

bash

Copy code

php bin/magento info:currency:list

List of Available Language Locales

bash

Copy code

php bin/magento info:language:list

Display the List of Available Timezones

bash

Copy code

php bin/magento info:timezone:list

14. Maintenance Mode

Enable Maintenance Mode

bash

Copy code

php bin/magento maintenance:enable

Enable Maintenance Mode for All Clients Except Specific IPs

bash

Copy code

php bin/magento maintenance:enable –ip

Take a backup of Magento Application code base, media, and database using the CLI:

php bin/magento setup:backup