magento2命令行大全

redmaomail 2024-07-24 18:14 阅读数 65 #Magento

红帽云邮外贸主机

在本教程中,我们将讨论Magento 2中的命令行接口(CLI)。如你所知,Magento 2在bin/magento添加了许多命令。

当你在终端运行命令时:

  
  1. php bin/magento

要么

  
  1. bin/magento

你将得到可用的Magento 2命令行列表,这个列表包括自定义的命令行

  
  1. Usage:
  2. command [options] [arguments]
  3. Options:
  4. --help (-h) Display this help message
  5. --quiet (-q) Do not output any message
  6. --verbose (-v|vv|vvv) Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
  7. --version (-V) Display this application version
  8. --ansi Force ANSI output
  9. --no-ansi Disable ANSI output
  10. --no-interaction (-n) Do not ask any interactive question
  11. Available commands:
  12. help Displays help for a command
  13. list Lists commands
  14. admin
  15. admin:user:create Creates an administrator
  16. admin:user:unlock Unlock Admin Account
  17. cache
  18. cache:clean Cleans cache type(s)
  19. cache:disable Disables cache type(s)
  20. cache:enable Enables cache type(s)
  21. cache:flush Flushes cache storage used by cache type(s)
  22. cache:status Checks cache status
  23. catalog
  24. catalog:images:resize Creates resized product images
  25. catalog:product:attributes:cleanup Removes unused product attributes.
  26. cron
  27. cron:run Runs jobs by schedule
  28. customer
  29. customer:hash:upgrade Upgrade customer's hash according to the latest algorithm
  30. deploy
  31. deploy:mode:set Set application mode.
  32. deploy:mode:show Displays current application mode.
  33. dev
  34. dev:source-theme:deploy Collects and publishes source files for theme.
  35. dev:tests:run Runs tests
  36. dev:urn-catalog:generate Generates the catalog of URNs to *.xsd mappings for the IDE to highlight xml.
  37. dev:xml:convert Converts XML file using XSL style sheets
  38. i18n
  39. i18n:collect-phrases Discovers phrases in the codebase
  40. i18n:pack Saves language package
  41. i18n:uninstall Uninstalls language packages
  42. indexer
  43. indexer:info Shows allowed Indexers
  44. indexer:reindex Reindexes Data
  45. indexer:reset Resets indexer status to invalid
  46. indexer:set-mode Sets index mode type
  47. indexer:show-mode Shows Index Mode
  48. indexer:status Shows status of Indexer
  49. info
  50. info:adminuri Displays the Magento Admin URI
  51. info:backups:list Prints list of available backup files
  52. info:currency:list Displays the list of available currencies
  53. info:dependencies:show-framework Shows number of dependencies on Magento framework
  54. info:dependencies:show-modules Shows number of dependencies between modules
  55. info:dependencies:show-modules-circular Shows number of circular dependencies between modules
  56. info:language:list Displays the list of available language locales
  57. info:timezone:list Displays the list of available timezones
  58. maintenance
  59. maintenance:allow-ips Sets maintenance mode exempt IPs
  60. maintenance:disable Disables maintenance mode
  61. maintenance:enable Enables maintenance mode
  62. maintenance:status Displays maintenance mode status
  63. module
  64. module:disable Disables specified modules
  65. module:enable Enables specified modules
  66. module:status Displays status of modules
  67. module:uninstall Uninstalls modules installed by composer
  68. sampledata
  69. sampledata:deploy Deploy sample data modules
  70. sampledata:remove Remove all sample data packages from composer.json
  71. sampledata:reset Reset all sample data modules for re-installation
  72. setup
  73. setup:backup Takes backup of Magento Application code base, media and database
  74. setup:config:set Creates or modifies the deployment configuration
  75. setup:cron:run Runs cron job scheduled for setup application
  76. setup:db-data:upgrade Installs and upgrades data in the DB
  77. setup:db-schema:upgrade Installs and upgrades the DB schema
  78. setup:db:status Checks if DB schema or data requires upgrade
  79. setup:di:compile Generates DI configuration and all missing classes that can be auto-generated
  80. setup:install Installs the Magento application
  81. setup:performance:generate-fixtures Generates fixtures
  82. setup:rollback Rolls back Magento Application codebase, media and database
  83. setup:static-content:deploy Deploys static view files
  84. setup:store-config:set Installs the store configuration
  85. setup:uninstall Uninstalls the Magento application
  86. setup:upgrade Upgrades the Magento application, DB data, and schema
  87. theme
  88. theme:uninstall Uninstalls theme

命令行类别

我们可以把这个列表分成以下几类:

  • Cache
  • Indexer
  • Cron job
  • Code compiler
  • Set the Magento mode
  • i18n translation
  • Run unit tests
  • Maintenance
  • module management
  • Setup: Install, Upgrade, Uninstall, Backup , Rollback
  • Theme
  • Deployment

接下来我们将举几个例子。

缓存命令行

如何检查缓存类型的状态
  
  1. php bin/magento cache:status

结果:

  
  1. config: 1
  2. layout: 1
  3. block_html: 1
  4. collections: 1
  5. db_ddl: 1
  6. eav: 1
  7. full_page: 1
  8. translate: 1
  9. config_integration: 1
  10. config_integration_api: 1
  11. config_webservice: 1
如何清理缓存类型
  
  1. php bin/magento cache:clean

结果:

  
  1. $ php bin/magento cache:clean
  2. Cleaned cache types:
  3. config
  4. layout
  5. block_html
  6. collections
  7. reflection
  8. db_ddl
  9. eav
  10. customer_notification
  11. full_page
  12. config_integration
  13. config_integration_api
  14. translate
  15. config_webservice
如何刷新缓存类型
  
  1. php bin/magento cache:flush
如何检查启用,禁用缓存类型
  
  1. php bin/magento cache:enable
  2. php bin/magento cache:disable

高级命令:

  
  1. magento cache:enable [type] ... [type]
  2. magento cache:disable [type] ... [type]

例如禁用整页缓存

  
  1. magento cache:disable full_page

索引器命令行

通过以下命令检查索引器状态

  
  1. php bin/magento indexer:info

我们会得到结果:

  
  1. design_config_grid Design Config Grid
  2. customer_grid Customer Grid
  3. catalog_category_product Category Products
  4. catalog_product_category Product Categories
  5. catalog_product_price Product Price
  6. catalog_product_attribute Product EAV
  7. catalogsearch_fulltext Catalog Search
  8. cataloginventory_stock Stock
  9. catalogrule_rule Catalog Rule Product
  10. catalogrule_product Catalog Product Rule
如何重建数据
  
  1. php bin/magento indexer:reindex
如何将索引器状态重置为无效
  
  1. php bin/magento indexer:reset
如何显示索引模式
  
  1. php bin/magento indexer:show-mode

结果:

  
  1. $ php bin/magento indexer:show-mode
  2.  
  3. Design Config Grid: Update on Save
  4. Customer Grid: Update on Save
  5. Category Products: Update on Save
  6. Product Categories: Update on Save
  7. Product Price: Update on Save
  8. Product EAV: Update on Save
  9. Catalog Search: Update on Save
  10. Stock: Update on Save
  11. Catalog Rule Product: Update on Save
  12. Catalog Product Rule: Update on Save
如何设置索引模式类型
  
  1. php bin/magento indexer:set-mode {realtime|schedule} [indexer]

例如:

  
  1. magento indexer:set-mode schedule catalog_category_product catalog_product_category

部署命令行

命令语法:

  
  1. php bin/magento setup:static-content:deploy <lang> ... <lang> [--dry-run]

如何运行部署静态内容

  
  1. php bin/magento setup:static-content:deploy

它将显示如下:

  
  1. $ php bin/magento setup:static-content:deploy
  2.  
  3. Requested languages: en_US
  4. === frontend -> Magento/blank -> en_US ===
  5. ........................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................

默认情况下,它将运行部署默认语言的静态内容: en_EN

如果您想部署其他语言的静态内容,例如: pt_BR

运行

  
  1. php bin/magento setup:static-content:deploy pt_BR

然后得到结果:

  
  1. Requested languages: pt_BR
  2. === frontend -> Magento/luma -> pt_BR ===
  3. ... progress indicator ...
  4. Successful: 1613 files; errors: 0
  5.  
  6. === frontend -> Magento/blank -> pt_BR ===
  7. ... progress indicator ...
  8. Successful: 1620 files; errors: 0
  9.  
  10. === adminhtml -> Magento/backend -> pt_BR ===
  11. ... progress indicator ...
  12. Successful: 1626 files; errors: 0
  13.  
  14. === Minify templates ===
  15. ... progress indicator ...
  16. Successful: 858 files modified
  17. ---

如何通过命令行获取管理路径

你知道吗?您可以获取管理路径而不访问etc/env.php文件。

运行

  
  1. php bin/magento info:adminuri

结果:

  
  1. $ php bin/magento info:adminuri
  2.  
  3. Admin URI: /admin

所以/admin现在的路径是,将您的浏览器导航到domain.com/admin以访问Magento 2后端。

如何通过命令行启用维护模式

启用维护模式

  
  1. php bin/magento maintenance:enable

结果:

  
  1. $ php bin/magento maintenance:enable
  2. Enabled maintenance mode

禁用维护模式

  
  1. php bin/magento maintenance:disable

允许IP访问商店

设置维护模式仅允许ip

  
  1. php bin/magento maintenance:allow-ips

例如:

  
  1. php bin/magento maintenance:allow-ips 168.168.168.168
  2. Set exempt IP-addresses: 168.168.168.168

如何设置Magento Developer模式或Product模式

显示当前的Magento 2模式

  
  1. php bin/magento deploy:mode:show

结果:

  
  1. $ php bin/magento deploy:mode:show
  2. Current application mode: default. (Note: Environment variables may override this value.)

目前,我们处于默认模式,让我们切换到开发人员模式

  
  1. php bin/magento deploy:mode:set developer

结果:

  
  1. $ php bin/magento deploy:mode:set developer
  2. Enabled developer mode.

恭喜!现在您的商店正在开发人员模式下运行。快乐编码;)


喜欢 (0)

红帽云邮外贸主机

分享到:
版权声明:本站内容源自互联网,如有内容侵犯了你的权益,请联系删除相关内容。
    红帽云邮外贸主机
热门
    红帽云邮外贸主机
    红帽云邮外贸主机