
このチュートリアルでは、Magento 2 のコマンドラインインターフェース (CLI) について説明します。 ご存知のように、Magento 2 では bin/magento に多くのコマンドが追加されました。これを理解するのは難しいかもしれませんが、このチュートリアルで詳しく説明しましょう。
ターミナルでコマンドを実行すると
php bin/magento
また
bin/magento
Magento 2で利用可能なコマンドラインのリストが表示され、このリストにはカスタムコマンドラインも含まれます。
Usage:
command [options] [arguments]
Options:
--help (-h) Display this help message
--quiet (-q) Do not output any message
--verbose (-v|vv|vvv) Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
--version (-V) Display this application version
--ansi Force ANSI output
--no-ansi Disable ANSI output
--no-interaction (-n) Do not ask any interactive question
Available commands:
help Displays help for a command
list Lists commands
admin
admin:user:create Creates an administrator
admin:user:unlock Unlock Admin Account
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.
cron
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:source-theme:deploy Collects and publishes source files for theme.
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
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-mode Sets index mode type
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
sampledata
sampledata:deploy Deploy sample data modules
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-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
setup:uninstall Uninstalls the Magento application
setup:upgrade Upgrades the Magento application, DB data, and schema
theme
theme:uninstall Uninstalls theme
目次
コマンドラインカテゴリー
以下のように分けられます:
- キャッシュ
- インデクサー
- クロンジョブ
- コードコンパイラ
- Magentoモードの設定
- 国際化のための翻訳
- ユニットテストの実行
- メンテナンス
- モジュール管理
- セットアップ インストール、アップグレード、アンインストール、バックアップ、ロールバック
- テーマ
- デプロイメント
キャッシュのコマンドライン
キャッシュタイプの状態を確認する方法
php bin/magento cache:status
結果
config: 1
layout: 1
block_html: 1
collections: 1
db_ddl: 1
eav: 1
full_page: 1
translate: 1
config_integration: 1
config_integration_api: 1
config_webservice: 1
キャッシュタイプの削除方法
php bin/magento cache:clean
結果
$ php bin/magento cache:clean
Cleaned cache types:
config
layout
block_html
collections
reflection
db_ddl
eav
customer_notification
full_page
config_integration
config_integration_api
translate
config_webservice
キャッシュタイプの洗い出し方法
php bin/magento cache:flush
キャッシュタイプの有効・無効の確認方法
php bin/magento cache:enable
php bin/magento cache:disable
アドバンストコマンドを使用します。
magento cache:enable [type] ... [type]
magento cache:disable [type] ... [type]
例:フルページキャッシュの無効化
magento cache:disable full_page
インデクサーのコマンドライン
以下のコマンドでインデクサーの状態を確認します:
php bin/magento indexer:info
結果を出します:
design_config_grid Design Config Grid
customer_grid Customer Grid
catalog_category_product Category Products
catalog_product_category Product Categories
catalog_product_price Product Price
catalog_product_attribute Product EAV
catalogsearch_fulltext Catalog Search
cataloginventory_stock Stock
catalogrule_rule Catalog Rule Product
catalogrule_product Catalog Product Rule
データの再インデックス化の方法
php bin/magento indexer:reindex
インデクサーのステータスを無効に戻す方法
php bin/magento indexer:reset
インデックスモードの表示方法
php bin/magento indexer:show-mode
結果
$ php bin/magento indexer:show-mode
Design Config Grid: Update on Save
Customer Grid: Update on Save
Category Products: Update on Save
Product Categories: Update on Save
Product Price: Update on Save
Product EAV: Update on Save
Catalog Search: Update on Save
Stock: Update on Save
Catalog Rule Product: Update on Save
Catalog Product Rule: Update on Save
インデックスモードタイプの設定方法
php bin/magento indexer:set-mode {realtime|schedule} [indexer]
例:
magento indexer:set-mode schedule catalog_category_product catalog_product_category
デプロイメントコマンドライン
コマンドの構文
php bin/magento setup:static-content:deploy <lang> ... <lang> [--dry-run]
スタティックコンテンツのデプロイを実行する方法
php bin/magento setup:static-content:deploy
以下のように表示されます:
$ php bin/magento setup:static-content:deploy
Requested languages: en_US
=== frontend -> Magento/blank -> en_US ===
...................................................................................
デフォルトでは、デフォルトの言語であるen_ENのスタティックコンテンツのデプロイを行います。
pt_BRなど、他の言語のスタティック・コンテンツを配置したい場合は
実行
php bin/magento setup:static-content:deploy pt_BR
そして、結果を得る:
Requested languages: pt_BR
=== frontend -> Magento/luma -> pt_BR ===
... progress indicator ...
Successful: 1613 files; errors: 0
=== frontend -> Magento/blank -> pt_BR ===
... progress indicator ...
Successful: 1620 files; errors: 0
=== adminhtml -> Magento/backend -> pt_BR ===
... progress indicator ...
Successful: 1626 files; errors: 0
=== Minify templates ===
... progress indicator ...
Successful: 858 files modified
---
コマンドラインで管理者のパスを取得する方法
ご存知ですか?etc/env.phpファイルにアクセスしなくても、管理者のパスを取得できます。
実行
php bin/magento info:adminuri
結果
$ php bin/magento info:adminuri
Admin URI: /admin
これでパスは/adminとなり、ブラウザでdomain.com/adminに移動してMagento 2のバックエンドにアクセスします。
コマンドラインでメンテナンスモードを有効にする方法
メンテナンスモードの有効化
php bin/magento maintenance:enable
結果
$ php bin/magento maintenance:enable
Enabled maintenance mode
メンテナンスモードの無効化
php bin/magento maintenance:disable
IPによるストアへのアクセスを許可する
メンテナンスモード対象外IPの設定
php bin/magento maintenance:allow-ips
例:
php bin/magento maintenance:allow-ips 168.168.168.168
Set exempt IP-addresses: 168.168.168.168
Magentoの開発者モードや製品モードを設定する方法
現在のMagento 2モードを表示
php bin/magento deploy:mode:show
結果
$ php bin/magento deploy:mode:show
Current application mode: default. (Note: Environment variables may override this value.)
現在、デフォルトモードになっていますが、開発者モードに切り替えましょう。
php bin/magento deploy:mode:set developer
結果
$ php bin/magento deploy:mode:set developer
Enabled developer mode.
おめでとうございます。これであなたのストアは開発者モードで動作しています。コーディングを楽しんでください