Search blog

Thursday, November 10, 2016

Magento 2 CLI/Terminal Commands

Commands for Magento 2x

If you are a Terminal/CLI ninja and have been seeking for nifty CLI commands, head forward!

Note: You may/may not have to enter 'sudo', depending on your folder permission settings. In my case I had to so I have added 'sudo' before each of my command.

>> To view Magento Help Commands:
php bin/magento

>> To view Magento Version: php bin/magento --version

>> To REINDEX CACHE: php bin/magento indexer:reindex

>> To Clean Cache:
php bin/magento cache:clean

- Cache Options: config , layout , block_html , collections , reflection , db_ddl , eav , customer_notification , full_page , config_integration , config_integration_api , translate , config_webservice

- Cache Options Usage:
  • php bin/magento cache:clean
  • php bin/magento cache:flush
  • php bin/magento cache:enable
  • php bin/magento cache:disable
  • php bin/magento cache:status
>> Maintenance Mode:
  • Sets maintenance mode exempt IPs: php bin/magento maintenance:allow-ips your_ip_address1 ip_address2
  • Disable Allowed IPs: php bin/magento maintenance:enable --ip=none
  • Disables maintenance mode: php bin/magento maintenance:disable 
  • Enable maintenance mode: php bin/magento maintenance:enable 
  • Displays maintenance mode status: php bin/magento maintenance:status
For more on Maintenance Mode, you may check Magento Guide at: http://devdocs.magento.com/guides/v2.0/install-gde/install/cli/install-cli-subcommands-maint.html

    >> Info:
    • Displays the Magento Admin URI: php bin/magento info:adminuri 
    • Displays the list of available currencies: php bin/magento info:currency:list 
    • Displays the list of available language locales: php bin/magento info:language:list 
    • Displays the list of available timezones: php bin/magento info:timezone:list

    >> Admin Solutions: 

      >> Module:

       NOTE: If you are disabling a module, first & foremost, check whether the particular module has any circular dependency.
       php bin/magento info:dependencies:show-modules-circular  
      
       The command above will generate one CSV file, please analyze this and make a decision. The file will be located in your DOCUMENT_ROOT folder bearing the filename 'modules-circular-dependencies.csv'.

      Also, while disabling an extension using the command below, it will throw an exception, if it has a circular dependency. - Source: https://magento.stackexchange.com/a/238338/58152
      • Disables specified modules: php bin/magento module:disable module_name --clear-static-content
      • Enables specified modules: php bin/magento module:enable module_name --clear-static-content
      • Displays status of modules: php bin/magento module:status 
      • Uninstalls modules installed by composer: sudo php bin/magento module:uninstall

      >> Setup:
      • Run CRON for Setup Application: php bin/magento setup:cron:run
      • Installs and upgrades data in the DB: php bin/magento setup:db-data:upgrade
      • Installs and upgrades the DB schema: php bin/magento setup:db-schema:upgrade
      • Checks if DB schema or data requires upgrade: php bin/magento setup:db:status
      • Generates DI configuration and all missing classes that can be auto-generated: php bin/magento setup:di:compile
      • Installs the Magento application: php bin/magento setup:install
      • Rolls back Magento Application codebase, media and database: php bin/magento setup:rollback
      • Deploys static view files: php bin/magento  setup:static-content:deploy
      • Installs the store configuration: php bin/magento setup:store-config:set
      • Uninstalls the Magento application: php bin/magento setup:uninstall
      • Upgrades the Magento application, DB data, and schema: php bin/magento setup:upgrade

      >> Backup:
      • Takes BACKUP of Magento Application code base, media and database: php bin/magento setup:backup
      •  View various backup options available: php bin/magento| grep backup
      •   View various backup options in detail: php bin/magento setup:backup --help
      Example to backup both code & data:
       php bin/magento setup:backup --code --db  
      
        Enable/Disable Backup from CLI:
        • Enable: php bin/magento config:set system/backup/functionality_enabled 1
        • Disable:  php bin/magento config:set system/backup/functionality_enabled 0

        >> Theme:
        Uninstall Theme: php bin/magento theme:uninstall theme_name

        Probably the above method is only applicable to themes that have been installed using composer. For other themes that haven't been installed using composer, please refer to the methods below:
        An important point I noticed from Reference 2 was this SQL query:

        There is a table in database named as theme.You can use the below code to delete your theme:

         USE dbname;  
         DELETE FROM theme where theme_id=5;  
        

        >> Deploy Static Content for Selected Theme:

        NOTE: Executing just the 4th command from the list below, will automatically run all the commands from 1 to 3.
        1. php bin/magento setup:static-content:deploy --theme Magento/backend en_US
        2. php bin/magento setup:static-content:deploy --theme frontend/Smartwave/porto en_US
        3. php bin/magento setup:static-content:deploy --theme Smartwave/porto_child en_US
        4. php bin/magento setup:static-content:deploy --theme Smartwave/porto_child

        >> Sample Data:
        • Deploy sample data modules: php bin/magento sampledata:deploy
        • Remove all sample data packages from composer.json: php bin/magento sampledata:remove
        • Reset all sample data modules for re-installation: php bin/magento sampledata:reset

        >> Magento Mode:
        • Display current mode: php bin/magento deploy:mode:show
        • Change mode: magento deploy:mode:set {mode} [-s|--skip-compilation]
          where
          {mode}
          is required; it can be either developer or production
          --skip-compilation is an optional parameter you can use to skip code compilation when you change to production mode.
          Example: php bin/magento deploy:mode:set production -s or php bin/magento deploy:mode:set developer
        • Change to production mode: magento deploy:mode:set production
        • Change to developer mode: If you’re changing from production mode to developer mode, delete the contents of the var/generation and var/di directories. Run the following command in your Magento Root Directory:

           rm -rf var/di/* var/generation/* var/cache/* var/page_cache/* var/view_preprocessed/* var/composer_home/cache/*
          
           php bin/magento deploy:mode:set developer 
            or
           php bin/magento module:enable [--force] Magento_Developer  
          


        >> Cron Job Hang/Stuck/Stopped
        If your cron job has got stuck or what is also known as hanged, you can run the commands below to resolve the issue. Sometimes, you might have to re-run all the 3 commands, in case the issue doesn't resolve in the 1st attempt:
        • php bin/magento setup:cron:run
        • php bin/magento cron:run
        • php update/cron.php

        No comments:

        Post a Comment

        Thank you for your Feedback!
        www.evagabond.me

        Top 5 Posts (Weekly)