craft コマンドの clear-caches/all で管理画面のキャッシュクリアのエラーが出る場合の対処法をご紹介します。
Craft CMS では、主要な操作をコマンドラインで実行できるツールが提供されています。
例えば、プラグインのインストールやデータベースのバックアップ、キャッシュのクリアなどがコマンドラインで簡単に行なえます。
このコマンドラインツールを使うには、予め Craft CMS のプロジェクト・ルートディレクトリにある craft
というファイルに実行権限を与えておく必要があります。
chmod +x ./craft
さて、今回、下記のコマンドで全てのキャッシュをクリアしようとしたところ、管理画面のキャッシュに関する下記のエラーが出てしまいました。
./craft clear-caches/all
Clearing cache: Asset caches
Clearing cache: Asset indexing data
Clearing cache: Asset transform index
Clearing cache: Compiled templates
Clearing cache: Control panel resources
Error clearing cache Control panel resources: Unable to clear control panel resources because the location isn't known for console commands.
Clearing cache: Data caches
Clearing cache: Temp files
これは、Craft CMS のデフォルトのディレクトリ構造と違う構成にした場合に発生します。この場合は、confit/general.php
に下記のように @webroot の場所を定義してあげることで解消します。
'aliases' => [
'@webroot' => dirname(__DIR__) . '/path-to-your-webroot',
],
ちなみに、dirname(__DIR__)
で階層を2つ上がる場合には dirname(__DIR__, 2)
とすれば良いようです。
参考: Unable to clear Control Panel resources using ./craft clear-caches/all · Issue #3787 · craftcms/cms
以上です。