M2常用命令

卸载m2

php bin/magento setup:uninstall

显示后台管理员URI

php bin/magento info:adminuri

卸载模块

比如插件名为Zou_Test

php bin/magento module:uninstall --clear-static-content Zou_Test

启用模块插件

比如插件名为Zou_Test

php bin/magento module:enable --clear-static-content Zou_Test

禁用模块插件

比如插件名为Zou_Test

php bin/magento module:disable --clear-static-content Zou_Test

插件列表(启用和禁用的)

php bin/magento module:status

切换到生产模式

php bin/magento deploy:mode:set production

切换到开发模式

php bin/magento deploy:mode:set developer

代码编译

检查代码是否有语法错误,比如调用的类是否存在等等。

bin/magento setup:di:compile 

生成静态文件

生成最新的静态文件到pub/static里去。
默认模式和生成模式必须要这些静态文件,不然就报错。

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

会自动生成默认语言(一般为英语)的静态文件。
也就是说上面这条命令只生成en_US的静态文件。

如果你想要同时生成英文和中文,需要在后面指定语言包名,就是:

bin/magento setup:static-content:deploy en_US zh_Hans_CN -f

这样的话 就会同时生成英文和中文的静态文件。

删除示例数据模块

php bin/magento sampledata:remove 

更新Magento数据库数据

比如你的插件里有自定义的表/添加了产品属性/更改了某个字段等等,凡是跟数据库表相关的数据。
都用这个命令来更新到数据库里去。

php bin/magento setup:upgrade

启用维护模式

php bin/magento maintenance:enable

禁用维护模式

php bin/magento maintenance:disable

重置索引

php bin/magento indexer:reset

刷新索引(reindex)

这个经常用到,要熟记。
有任何分类/产品的报错/数据不对 都可以用这个解决。
后台不识别主题的话 也可以用这个解决。
产品库存数据不对的话 也可以用这个解决。
等等,反正遇到数据库表相关的报错 都可以优先用它来解决。

php bin/magento indexer:reindex

刷新Magento缓存

php bin/magento cache:clean && php bin/magento cache:flush

创建后台管理员账号

php bin/magento admin:user:create --admin-user='管理员用户名' --admin-password='密码' --admin-email='邮箱' --admin-firstname='名' --admin-lastname='姓'

比如:

php bin/magento admin:user:create --admin-user='muneeb' --admin-password='magento123!' --admin-email='muneeb@magenticians.com' --admin-firstname='Syed' --admin-lastname='Muneeb'

解锁后台管理员帐户

php bin/magento admin:user:unlock admin

备份文件系统和数据库

php bin/magento setup:backup --code --db

回滚

php bin/magento info:backups:list

例如,要还原名为的媒体备份1440611839_filesystem_media.tgz,请输入
php bin/magento setup:rollback -m 1440611839_filesystem_media.tgz

卸载主题

php bin/magento theme:uninstall [--backup-code] [-c|--clear-static-content] {theme path} ... {theme path}

  • {theme path}是主题的相对路径。例如,Magento 2提供的Blank主题的路径是frontend/Magento/blank
  • --backup-code 备份Magento 2代码库,放在var/backups/<timestamp>_filesystem.tgz下。
  • --clear-static-content 清除生成的静态视图文件。

同时卸载两个主题:

php bin/magento theme:uninstall frontend/ExampleCorp/SampleModuleTheme frontend/ExampleCorp/SampleModuleThemeDepend --backup-code --clear-static-content

卸载语言包

php bin/magento i18n:uninstall [-b|--backup-code] {language package name} ... {language package name}
  • --backup-code 备份Magento 2代码库,放在var/backups/<timestamp>_filesystem.tgz下。
    同时卸载两个语言包:
    magento i18n:uninstall vendorname/language-en_us vendorname/language-en_gb --backup-code

生成varnish配置文件

php bin/magento varnish:vcl:generate

修改配置文件

比如修改base-url

php bin/magento setup:store-config:set --base-url="http://localhost:8080/"
php bin/magento setup:store-config:set --base-url-secure="https://localhost:8080/"

更新系统

终结者命令,能解决90%的问题。

php bin/magento maintenance:enable 

rm -rf var/di/* && rm -rf var/generation/* && rm -rf var/cache/* && rm -rf var/page_cache/* && rm -rf var/view_preprocessed/* && rm -rf pub/static/* && rm -rf generated/* && mkdir var/di

php bin/magento setup:upgrade && php bin/magento setup:di:compile

php bin/magento setup:static-content:deploy -f && php bin/magento indexer:reindex && php bin/magento maintenance:disable && php bin/magento cache:clean && php bin/magento cache:flush

其他

1)2.3.0自带命令列表

Magento CLI 2.3.0
Usage:
  command [options] [arguments]
Options:
  -h, --help            Display this help message
  -q, --quiet           Do not output any message
  -V, --version         Display this application version
      --ansi            Force ANSI output
      --no-ansi         Disable ANSI output
  -n, --no-interaction  Do not ask any interactive question
  -v|vv|vvv, --verbose  Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
Available commands:
  help                                     Displays help for a command
  list                                     Lists commands
 admin
  admin:user:create                        Creates an administrator
  admin:user:unlock                        Unlock Admin Account
 app
  app:config:dump                          Create dump of application
  app:config:import                        Import data from shared configuration files to appropriate data storage
  app:config:status                        Checks if config propagation requires update
 cache
  cache:clean                              Cleans cache type(s)
  cache:disable                            Disables cache type(s)
  cache:enable                             Enables cache type(s)
  cache:flush                              Flushes cache storage used by cache type(s)
  cache:status                             Checks cache status
 catalog
  catalog:images:resize                    Creates resized product images
  catalog:product:attributes:cleanup       Removes unused product attributes.
 config
  config:sensitive:set                     Set sensitive configuration values
  config:set                               Change system configuration
  config:show                              Shows configuration value for given path. If path is not specified, all saved values will be shown
 cron
  cron:install                             Generates and installs crontab for current user
  cron:remove                              Removes tasks from crontab
  cron:run                                 Runs jobs by schedule
 customer
  customer:hash:upgrade                    Upgrade customer's hash according to the latest algorithm
 deploy
  deploy:mode:set                          Set application mode.
  deploy:mode:show                         Displays current application mode.
 dev
  dev:di:info                              Provides information on Dependency Injection configuration for the Command.
  dev:profiler:disable                     Disable the profiler.
  dev:profiler:enable                      Enable the profiler.
  dev:query-log:disable                    Disable DB query logging
  dev:query-log:enable                     Enable DB query logging
  dev:source-theme:deploy                  Collects and publishes source files for theme.
  dev:template-hints:disable               Disable frontend template hints. A cache flush might be required.
  dev:template-hints:enable                Enable frontend template hints. A cache flush might be required.
  dev:tests:run                            Runs tests
  dev:urn-catalog:generate                 Generates the catalog of URNs to *.xsd mappings for the IDE to highlight xml.
  dev:xml:convert                          Converts XML file using XSL style sheets
 encryption
  encryption:payment-data:update           Re-encrypts encrypted credit card data with latest encryption cipher.
 i18n
  i18n:collect-phrases                     Discovers phrases in the codebase
  i18n:pack                                Saves language package
  i18n:uninstall                           Uninstalls language packages
 indexer
  indexer:info                             Shows allowed Indexers
  indexer:reindex                          Reindexes Data
  indexer:reset                            Resets indexer status to invalid
  indexer:set-dimensions-mode              Set Indexer Dimensions Mode
  indexer:set-mode                         Sets index mode type
  indexer:show-dimensions-mode             Shows Indexer Dimension Mode
  indexer:show-mode                        Shows Index Mode
  indexer:status                           Shows status of Indexer
 info
  info:adminuri                            Displays the Magento Admin URI
  info:backups:list                        Prints list of available backup files
  info:currency:list                       Displays the list of available currencies
  info:dependencies:show-framework         Shows number of dependencies on Magento framework
  info:dependencies:show-modules           Shows number of dependencies between modules
  info:dependencies:show-modules-circular  Shows number of circular dependencies between modules
  info:language:list                       Displays the list of available language locales
  info:timezone:list                       Displays the list of available timezones
 maintenance
  maintenance:allow-ips                    Sets maintenance mode exempt IPs
  maintenance:disable                      Disables maintenance mode
  maintenance:enable                       Enables maintenance mode
  maintenance:status                       Displays maintenance mode status
 module
  module:disable                           Disables specified modules
  module:enable                            Enables specified modules
  module:status                            Displays status of modules
  module:uninstall                         Uninstalls modules installed by composer
 msp
  msp:security:recaptcha:disable           Disable backend reCaptcha
  msp:security:tfa:disable                 Globally disable two factor auth
  msp:security:tfa:providers               List all available providers
  msp:security:tfa:reset                   Reset configuration for one user
 newrelic
  newrelic:create:deploy-marker            Check the deploy queue for entries and create an appropriate deploy marker.
 queue
  queue:consumers:list                     List of MessageQueue consumers
  queue:consumers:start                    Start MessageQueue consumer
 sampledata
  sampledata:deploy                        Deploy sample data modules for composer-based Magento installations
  sampledata:remove                        Remove all sample data packages from composer.json
  sampledata:reset                         Reset all sample data modules for re-installation
 setup
  setup:backup                             Takes backup of Magento Application code base, media and database
  setup:config:set                         Creates or modifies the deployment configuration
  setup:cron:run                           Runs cron job scheduled for setup application
  setup:db-data:upgrade                    Installs and upgrades data in the DB
  setup:db-declaration:generate-patch      Generate patch and put it in specific folder.
  setup:db-declaration:generate-whitelist  Generate whitelist of tables and columns that are allowed to be edited by declaration installer
  setup:db-schema:upgrade                  Installs and upgrades the DB schema
  setup:db:status                          Checks if DB schema or data requires upgrade
  setup:di:compile                         Generates DI configuration and all missing classes that can be auto-generated
  setup:install                            Installs the Magento application
  setup:performance:generate-fixtures      Generates fixtures
  setup:rollback                           Rolls back Magento Application codebase, media and database
  setup:static-content:deploy              Deploys static view files
  setup:store-config:set                   Installs the store configuration. Deprecated since 2.2.0. Use config:set instead
  setup:uninstall                          Uninstalls the Magento application
  setup:upgrade                            Upgrades the Magento application, DB data, and schema
 store
  store:list                               Displays the list of stores
  store:website:list                       Displays the list of websites
 theme
  theme:uninstall                          Uninstalls theme
 varnish
  varnish:vcl:generate                     Generates Varnish VCL and echos it to the command line
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值