Console Commands

While most of your interaction with Craft happens in a browser, a number of important tools are available via command line interface (CLI) actions that are run in a terminal.

This can be useful for automating tasks with cron, running actions in a deployment process (opens new window), working with Craft via SSH, and running resource-intensive tasks that might otherwise be constrained by the limits of your web server.

The Craft console application (craft) lives in the root of your project and requires PHP to run.

You may need to configure your environment in order to run PHP from your terminal; php-fpm and mod_php are meant to run with a web server while php-cli is a separate process for the command line.

Running php craft without any arguments will output a complete list of available options.

$ php craft

This is Yii version 2.0.36.

The following commands are available:

- db                                    Performs database operations.
    db/backup                           Creates a new database backup.
    db/convert-charset                  Converts tables’ character sets and collations. (MySQL only)
    db/restore                          Restores a database backup.

- cache                                 Allows you to flush cache.
    cache/flush                         Flushes given cache components.
    cache/flush-all                     Flushes all caches registered in the system.
    cache/flush-schema                  Clears DB schema cache for a given connection
                                        component.
    cache/index (default)               Lists the caches that can be flushed.

...

To see the help of each command, enter:

  craft help <command-name>

You can also run php craft help <command-name> to learn more about a command and whatever parameters and options it may accept.

See the Console Commands page in the Extending Craft section to learn about adding your own console commands.

While the complete list of available commands will include those from any plugins or custom modules you’ve added to your project, the following are Craft’s default console commands:

# cache

Allows you to flush caches.

# cache/flush

Flushes given cache components.

Example:

# flushes caches by ID: “first”, “second”, “third”
php craft cache/flush first second third

# cache/flush-all

Flushes all caches registered in the system.

# cache/flush-schema

Clears DB schema cache for a given connection component.

php craft cache/flush-schema
# identical to `php craft cache/flush-schema db`

Parameters

componentId
ID of the connection component. (Defaults to db.)

# cache

Lists the caches that can be flushed.

# clear-caches

Allows you to clear various Craft caches.

# clear-caches/all

Clear all caches.

# clear-caches/asset

Clears Asset caches.

# clear-caches/asset-indexing-data

Clears Asset indexing data.

# clear-caches/compiled-classes

Clears compiled classes.

# clear-caches/compiled-templates

Clears compiled templates.

# clear-caches/cp-resources

Clears control panel resources.

# clear-caches/data

Clears data caches.

# clear-caches

Lists the caches that can be cleared.

# clear-caches/temp-files

Clears temporary files.

# clear-caches/transform-indexes

Clears the Asset transform index.

# clear-deprecations

# clear-deprecations

Clears all deprecation warnings.

# db

Performs database operations.

# db/backup

Creates a new database backup.

Example:

php craft db/backup ./my-backups/

Parameters

path

The path the database backup should be created at. Can be any of the following:

  • A full file path
  • A folder path (backup will be saved in there with a dynamically-generated name)
  • A filename (backup will be saved in the working directory with the given name)
  • Blank (backup will be saved to the storage/backups/ folder with a dynamically-generated name)

Options

--zip
Whether the backup should be saved as a zip file.
--overwrite
Whether to overwrite an existing backup file, if a specific file path is given.

# db/convert-charset

Converts tables’ character sets and collations. (MySQL only)

Example:

php craft db/convert-charset utf8 utf8_unicode_ci

Parameters

charset
The target character set, which honors DbConfig::$charset or defaults to utf8.
collation
The target collation, which honors DbConfig::$collation or defaults to utf8_unicode_ci.

# db/restore

Restores a database backup.

Example:

php craft db/restore ./my-backup.sql

Parameters

path
The path to the database backup file.

# fixture

Allows you to manage test fixtures.

# fixture/load

Loads the specified fixture data.

Example:

# load User fixture data (any existing fixture data will be removed first)
php craft fixture/load "User"

# load all available fixtures found under 'tests\unit\fixtures'
php craft fixture/load "*"

# load all fixtures except User
php craft fixture/load "*, -User"

Parameters

fixturesInput
Array of fixtures to load.

Options

--global-fixtures, -g
Array of global fixtures that should be applied when loading and unloading. Set to InitDbFixture by default, which disables and enables integrity check so your data can be safely loaded.
--namespace, -n
Namespace to search for fixtures. Defaults to tests\unit\fixtures.

# fixture/unload

Unloads the specified fixtures.

Example:

# unload User fixture data
php craft fixture/load "User"

# unload all fixtures found under 'tests\unit\fixtures'
php craft fixture/load "*"

# unload all fixtures except User
php craft fixture/load "*, -User"

Parameters

fixturesInput
Array of fixtures to unload.

Options

--global-fixtures, -g
Array of global fixtures that should be applied when loading and unloading. Set to InitDbFixture by default, which disables and enables integrity check so your data can be safely loaded.
--namespace, -n
Namespace to search for fixtures. Defaults to tests\unit\fixtures.

# gc

# gc/run

Runs garbage collection.

Options

--delete-all-trashed
Whether all soft-deleted items should be deleted, rather than just the ones that were deleted long enough ago to be ready for hard-deletion per the softDeleteDuration config setting.
--empty-deprecated-tables
Whether old database tables should be emptied out.

# graphql

Allows you to manage GraphQL schemas.

# graphql/create-token

Creates a new authorization token for a schema.

Parameters

schemaUid
The schema UUID

Options

--name
The schema name
--expiry
Expiry date

# graphql/dump-schema

Dumps a given GraphQL schema to a file.

Options

--schema
The GraphQL schema UUID.
--token
The token to look up to determine the appropriate GraphQL schema.
--full-schema
Whether full schema should be printed or dumped.

# graphql/list-schemas

Lists all GraphQL schemas.

# graphql/print-schema

Prints a given GraphQL schema.

Options

--schema
The GraphQL schema UUID.
--token
The token to look up to determine the appropriate GraphQL schema.
--full-schema
Whether full schema should be printed or dumped.

# help

Provides help information about console commands.

# help

Displays available commands or the detailed information about a particular command.

Example:

$ php craft help db/backup

DESCRIPTION

Creates a new database backup.

Example:
php craft db/backup ./my-backups/


USAGE

craft db/backup [path] [...options...]

- path: string
  The path the database backup should be created at.
  Can be any of the following:

  - A full file path
  - A folder path (backup will be saved in there with a dynamically-generated name)
  - A filename (backup will be saved in the working directory with the given name)
  - Blank (backup will be saved to the `storage/backups/` folder with a dynamically-generated name)


OPTIONS

--appconfig: string
  custom application configuration file path.
  If not set, default application configuration is used.

--color: boolean, 0 or 1
  whether to enable ANSI color in the output.
  If not set, ANSI color will only be enabled for terminals that support it.

--help, -h: boolean, 0 or 1 (defaults to 0)
  whether to display help information about current command.

--interactive: boolean, 0 or 1 (defaults to 1)
  whether to run the command interactively.

--overwrite: boolean, 0 or 1 (defaults to 0)
  Whether to overwrite an existing backup file, if a specific file path is given.

--silent-exit-on-exception: boolean, 0 or 1
  if true - script finish with `ExitCode::OK` in case of exception.
  false - `ExitCode::UNSPECIFIED_ERROR`.
  Default: `YII_ENV_TEST`

--zip: boolean, 0 or 1 (defaults to 0)
  Whether the backup should be saved as a zip file.

$

Parameters

command
The name of the command to show help about. If not provided, all available commands will be displayed.

Options

--as-json, -j
Should the commands help be returned in JSON format?

# help/list

Lists all available controllers and actions in machine-readable format.

# help/list-action-options

List all available options for action in machine-readable format.

Parameters

action
Route to action.

# help/usage

Displays usage information for action.

Parameters

action
Route to action.

# index-assets

Allows you to re-index assets in volumes.

# index-assets/all

Re-indexes assets across all volumes.

Options

--cache-remote-images
Whether remote-stored images should be locally cached in the process.
--create-missing-assets
Whether to auto-create new asset records when missing.
--delete-missing-assets
Whether to delete all the asset records that have their files missing.

# index-assets/one

Re-indexes assets from the given volume handle.

Parameters

handle
The handle of the volume to index. You can optionally provide a volume sub-path, e.g. php craft index-assets/one volume-handle/path/to/folder.
startAt
Index of the asset to start with, which defaults to 0.

Options

--cache-remote-images
Whether remote-stored images should be locally cached in the process.
--create-missing-assets
Whether to auto-create new asset records when missing.
--delete-missing-assets
Whether to delete all the asset records that have their files missing.

# install

Craft CMS CLI installer.

# install/check

Checks whether Craft is already installed.

# install/craft

Runs the install migration.

Options

--email
The default email address for the first user to create during install.
--username
The default username for the first user to create during install.
--password
The default password for the first user to create during install.
--site-name
The default site name for the first site to create during install.
--site-url
The default site URL for the first site to create during install.
--language
The default langcode for the first site to create during install.

# invalidate-tags

Allows you to invalidate cache tags.

# invalidate-tags/all

Invalidates all cache tags.

# invalidate-tags/graphql

Invalidates all GraphQL query cache tags.

# invalidate-tags

Lists the cache tags that can be invalidated.

# invalidate-tags/template

Invalidates all template cache tags.

# mailer

# mailer/test

Tests sending an email with the current mailer settings.

Options

--to
Email address that should receive the test message.

# migrate

Manages Craft and plugin migrations.

# migrate/all

Runs all pending Craft, plugin, and content migrations.

Options

--no-content
Exclude pending content migrations.
--no-backup
Skip backing up the database.

# migrate/create

Creates a new migration.

This command creates a new migration using the available migration template. After using this command, developers should modify the created migration skeleton by filling up the actual migration logic.

craft migrate/create create_news_section

By default, the migration is created in the project’s migrations/ folder (as a “content migration”).
Use --plugin=<plugin-handle> to create a new plugin migration.
Use --type=app to create a new Craft CMS app migration.

Parameters

name
the name of the new migration. This should only contain letters, digits, and underscores.

Options

--track

The migration track to work with (e.g. craft, content, plugin:commerce, etc.)

Defaults to content, or automatically set to the plugin’s track when --plugin is passed.

--plugin, -p

The handle of the plugin to use during migration operations, or the plugin itself.

--template-file

The template file for generating new migrations. This can be either a path alias (e.g. @app/migrations/template.php) or a file path. Defaults to vendor/craftcms/cms/src/updates/migration.php.template.

# migrate/down

Downgrades Craft by reverting old migrations.

Example:

php craft migrate/down      # revert last migration
php craft migrate/down 3    # revert last three migrations
php craft migrate/down all  # revert all migrations

Parameters

limit
The number of migrations to be reverted. Defaults to 1, meaning the last applied migration will be reverted. When value is all, all migrations will be reverted.

Options

--track

The migration track to work with (e.g. craft, content, plugin:commerce, etc.)

Defaults to content, or automatically set to the plugin’s track when --plugin is passed.

--plugin, -p

The handle of the plugin to use during migration operations, or the plugin itself.

# migrate/history

Shows the list of migrations that have been applied so far.

Example:

php craft migrate/history      # displays the last ten migrations
php craft migrate/history 5    # displays the last five migrations
php craft migrate/history all  # displays the entire migration history

Parameters

limit
The maximum number of migrations to be displayed. (Defaults to 10.)
If all, the whole migration history will be displayed.

Options

--track

The migration track to work with (e.g. craft, content, plugin:commerce, etc.)

Defaults to content, or automatically set to the plugin’s track when --plugin is passed.

--plugin, -p

The handle of the plugin to use during migration operations, or the plugin itself.

# migrate/mark

Modifies the migration history to the specified version.

No actual migration will be performed.

php craft migrate/mark 101129_185401                          # using timestamp
php craft migrate/mark m101129_185401_create_user_table       # using name
php craft migrate/mark app\migrations\M101129185401CreateUser # using namespace name
php craft migrate/mark m000000_000000_base                    # reset entire history

Parameters

version

The version at which the migration history should be marked, which can be either the timestamp or the full name of the migration.

Specify m000000_000000_base to set the migration history to a state where no migration has been applied.

Options

--track

The migration track to work with (e.g. craft, content, plugin:commerce, etc.)

Defaults to content, or automatically set to the plugin’s track when --plugin is passed.

--plugin, -p

The handle of the plugin to use during migration operations, or the plugin itself.

# migrate/new

Shows any new migrations that have not been applied.

Example:

php craft migrate/new     # displays the first 10 new migrations
php craft migrate/new 5   # displays the first 5 new migrations
php craft migrate/new all # displays all new migrations

Parameters

limit
The maximum number of new migrations to be displayed. (Defaults to 10.)
If all, then every available new migration will be displayed.

Options

--track

The migration track to work with (e.g. craft, content, plugin:commerce, etc.)

Defaults to content, or automatically set to the plugin’s track when --plugin is passed.

--plugin, -p

The handle of the plugin to use during migration operations, or the plugin itself.

# migrate/redo

Reapplies previous migrations by first reverting them and then applying them again.

Example:

php craft migrate/redo     # redo the last applied migration
php craft migrate/redo 3   # redo the last three applied migrations
php craft migrate/redo all # redo all migrations

Parameters

limit
The number of migrations to be redone. Defaults to 1, meaning the last applied migration will be redone. When all, every migration will be redone.

Options

--track

The migration track to work with (e.g. craft, content, plugin:commerce, etc.)

Defaults to content, or automatically set to the plugin’s track when --plugin is passed.

--plugin, -p

The handle of the plugin to use during migration operations, or the plugin itself.

# migrate/to

Upgrades or downgrades until the specified version.

You can downgrade versions to a past apply time by providing a UNIX timestamp or a strtotime() (opens new window)-parseable value. All versions applied after that specified time will then be reverted.

Example:

php craft migrate/to 101129_185401                          # migration timestamp
php craft migrate/to m101129_185401_create_user_table       # full name
php craft migrate/to 1392853618                             # UNIX timestamp
php craft migrate/to "2022-02-02 02:02:02"                  # strtotime()-parseable
php craft migrate/to app\migrations\M101129185401CreateUser # full namespace name

Parameters

version
Either the version name or a past time value to be migrated to. This can be a timestamp, the full name of the migration, a UNIX timestamp, or a string value that can be parsed by strotime() (opens new window).

Options

--track

The migration track to work with (e.g. craft, content, plugin:commerce, etc.)

Defaults to content, or automatically set to the plugin’s track when --plugin is passed.

--plugin, -p

The handle of the plugin to use during migration operations, or the plugin itself.

# migrate/up

Upgrades Craft by applying new migrations.

Example:

php craft migrate     # apply all new migrations
php craft migrate 3   # apply the first 3 new migrations

Parameters

limit
The number of new migrations to be applied. If 0, every new migration will be applied.

Options

--track

The migration track to work with (e.g. craft, content, plugin:commerce, etc.)

Defaults to content, or automatically set to the plugin’s track when --plugin is passed.

--plugin, -p

The handle of the plugin to use during migration operations, or the plugin itself.

# off

# off

Disables system.live project config value—bypassing any allowAdminChanges config setting restrictions—meant for temporary use during the deployment process.

Options

--retry

Number of seconds the Retry-After HTTP header should be set to for 503 responses.

The retryDuration config setting can be used to configure a system-wide Retry-After header.

The isSystemLive config setting takes precedence over the system.live project config value, so if config/general.php sets isSystemLive to true or false these on/off commands error out.

Example

Running the following takes the system offline and returns 503 responses until it’s switched on again:

$ php craft off --retry=60
The system is now offline.
The retry duration is now set to 60.

# on

# on

Turns the system on.

Example:

$ php craft on
The system is now online.

# plugin

Manages plugins.

# plugin/disable

Disables a plugin.

$ php craft plugin/disable

The following plugins are enabled:

    Handle         Name            Version
    -------------  --------------  -------
    apple-news     Apple News      2.0.1
    ckeditor       CKEditor        1.3.0
    commerce       Craft Commerce  3.4.11
    gatsby-helper  Gatsby Helper   1.1.2

Choose a plugin handle to disable: ckeditor
*** disabling ckeditor
*** disabled ckeditor successfully (time: 0.003s)

Parameters

handle
The plugin handle.

# plugin/enable

Enables a plugin.

$ php craft plugin/enable

The following plugins are disabled:

    Handle      Name        Version
    ----------  ----------  -------
    apple-news  Apple News  2.0.1
    ckeditor    CKEditor    1.3.0

Choose a plugin handle to enable: ckeditor
*** enabling ckeditor
*** enabled ckeditor successfully (time: 0.004s)

Parameters

handle
The plugin handle.

# plugin/install

Installs a plugin.

$ php craft plugin/install

The following uninstalled plugins are present:

    Handle         Name            Version
    -------------  --------------  -------
    anchors        Anchors         2.3.1
    apple-news     Apple News      2.0.1
    ckeditor       CKEditor        1.3.0
    commerce       Craft Commerce  3.4.11
    gatsby-helper  Gatsby Helper   1.1.2

Choose a plugin handle to install: ckeditor
*** installing ckeditor
*** installed ckeditor successfully (time: 0.496s)

Parameters

handle
The plugin handle.

# plugin/list

Lists all plugins.

$ php craft plugin/list

    Name            Handle         Package Name            Version  Installed  Enabled
    --------------  -------------  ----------------------  -------  ---------  -------
    Anchors         anchors        craftcms/anchors        2.3.1    Yes        Yes
    Apple News      apple-news     craftcms/apple-news     2.0.1    Yes        Yes
    CKEditor        ckeditor       craftcms/ckeditor       1.3.0    Yes        Yes
    Craft Commerce  commerce       craftcms/commerce       3.4.11   Yes        Yes
    Gatsby Helper   gatsby-helper  craftcms/gatsby-helper  1.1.2    Yes        Yes

# plugin/uninstall

Uninstalls a plugin.

$ php craft plugin/uninstall

The following plugins plugins are installed and enabled:

    Handle         Name            Version
    -------------  --------------  -------
    anchors        Anchors         2.3.1
    apple-news     Apple News      2.0.1
    ckeditor       CKEditor        1.3.0
    commerce       Craft Commerce  3.4.11
    gatsby-helper  Gatsby Helper   1.1.2

Choose a plugin handle to uninstall: ckeditor
*** uninstalling ckeditor
*** uninstalled ckeditor successfully (time: 0.496s)

Parameters

handle
The plugin handle.

Options

--force
Whether the plugin uninstallation should be forced.

# project-config

Manages the Project Config.

# project-config/apply

Applies project config file changes.

Options

--force
Whether every entry change should be force-applied.

# project-config/diff

Prints a diff of the pending project config YAML changes.

Options

--invert
Whether to treat the loaded project config as the source of truth, instead of the YAML files.

# project-config/export

Exports the entire project config to a single file.

Parameters

path

The path the project config should be exported to. Can be any of the following:

  • A full file path
  • A folder path (export will be saved in there with a dynamically-generated name)
  • A filename (export will be saved in the working directory with the given name)
  • Blank (export will be saved in the working directly with a dynamically-generated name)

Options

--external
Whether to export the external project config data, from the config/project/ folder
--overwrite
Whether to overwrite an existing export file, if a specific file path is given.

# project-config/rebuild

Rebuilds the project config.

# project-config/touch

Updates the dateModified value in config/project/project.yaml, attempting to resolve a Git conflict for it.

# project-config/write

Writes out the currently-loaded project config as YAML files to the config/project/ folder, discarding any pending YAML changes.

# queue

Manages the queue.

# queue/exec

Executes a job. The command is internal, and used to isolate a job execution. Manual usage is not provided.

Parameters

id
of a message
ttr
time to reserve
attempt
number
pid
of a worker

Options

--verbose, -v
verbose mode of a job execute. If enabled, execute result of each job will be printed.

# queue/info

Info about queue status.

# queue/listen

Listens for new jobs added to the queue and runs them.

Parameters

timeout
The number of seconds to wait between cycles.

Options

--verbose, -v
verbose mode of a job execute. If enabled, execute result of each job will be printed.
--isolate
isolate mode. It executes a job in a child process.
--php-binary
path to php interpreter that uses to run child processes. If it is undefined, PHP_BINARY will be used.

# queue/release

Releases job(s) from the queue.

Example:

php craft queue/release all

Parameters

job
The job ID to release. Pass all to release all jobs.

# queue/retry

Re-adds failed job(s) to the queue.

Parameters

job
The job ID that should be retried, or all to retry all failed jobs.

# queue/run

Runs all jobs in the queue.

Options

--verbose, -v
verbose mode of a job execute. If enabled, execute result of each job will be printed.
--isolate
isolate mode. It executes a job in a child process.
--php-binary
path to php interpreter that uses to run child processes. If it is undefined, PHP_BINARY will be used.

# resave

Allows you to bulk-save elements.

# resave/assets

Re-saves assets.

Options

--queue

Whether the elements should be resaved via a queue job.

--element-id

The ID(s) of the elements to resave.

--uid

The UUID(s) of the elements to resave.

--site

The site handle to save elements from.

--status

The status(es) of elements to resave. Can be set to multiple comma-separated statuses.

--offset

The number of elements to skip.

--limit

The number of elements to resave.

--update-search-index

Whether to update the search indexes for the resaved elements.

--touch

Whether to update the dateUpdated timestamp for the elements.

--volume

The volume handle(s) to save assets from. Can be set to multiple comma-separated volumes.

--set

An attribute name that should be set for each of the elements. The value will be determined by --to.

--to

The value that should be set on the --set attribute.

The following value types are supported:

  • An attribute name: --to myCustomField
  • An object template: --to "={myCustomField|lower}"
  • A raw value: --to "=foo bar"
  • A PHP arrow function: --to "fn($element) => $element->callSomething()"
  • An empty value: --to :empty:
--if-empty

Whether the --set attribute should only be set if it doesn’t have a value.

# resave/categories

Re-saves categories.

Options

--queue

Whether the elements should be resaved via a queue job.

--element-id

The ID(s) of the elements to resave.

--uid

The UUID(s) of the elements to resave.

--site

The site handle to save elements from.

--status

The status(es) of elements to resave. Can be set to multiple comma-separated statuses.

--offset

The number of elements to skip.

--limit

The number of elements to resave.

--update-search-index

Whether to update the search indexes for the resaved elements.

--touch

Whether to update the dateUpdated timestamp for the elements.

--group

The group handle(s) to save categories/tags/users from. Can be set to multiple comma-separated groups.

--set

An attribute name that should be set for each of the elements. The value will be determined by --to.

--to

The value that should be set on the --set attribute.

The following value types are supported:

  • An attribute name: --to myCustomField
  • An object template: --to "={myCustomField|lower}"
  • A raw value: --to "=foo bar"
  • A PHP arrow function: --to "fn($element) => $element->callSomething()"
  • An empty value: --to :empty:
--if-empty

Whether the --set attribute should only be set if it doesn’t have a value.

# resave/entries

Re-saves entries.

Options

--queue

Whether the elements should be resaved via a queue job.

--drafts

Whether to resave element drafts.

--provisional-drafts

Whether to resave provisional element drafts.

--revisions

Whether to resave element revisions.

--element-id

The ID(s) of the elements to resave.

--uid

The UUID(s) of the elements to resave.

--site

The site handle to save elements from.

--status

The status(es) of elements to resave. Can be set to multiple comma-separated statuses.

--offset

The number of elements to skip.

--limit

The number of elements to resave.

--update-search-index

Whether to update the search indexes for the resaved elements.

--touch

Whether to update the dateUpdated timestamp for the elements.

--section

The section handle(s) to save entries from. Can be set to multiple comma-separated sections.

--type

The type handle(s) of the elements to resave.

--set

An attribute name that should be set for each of the elements. The value will be determined by --to.

--to

The value that should be set on the --set attribute.

The following value types are supported:

  • An attribute name: --to myCustomField
  • An object template: --to "={myCustomField|lower}"
  • A raw value: --to "=foo bar"
  • A PHP arrow function: --to "fn($element) => $element->callSomething()"
  • An empty value: --to :empty:
--if-empty

Whether the --set attribute should only be set if it doesn’t have a value.

# resave/matrix-blocks

Re-saves Matrix blocks.

You must supply the --field or --element-id argument for this to work properly.

Options

--queue

Whether the elements should be resaved via a queue job.

--element-id

The ID(s) of the elements to resave.

--uid

The UUID(s) of the elements to resave.

--site

The site handle to save elements from.

--status

The status(es) of elements to resave. Can be set to multiple comma-separated statuses.

--offset

The number of elements to skip.

--limit

The number of elements to resave.

--update-search-index

Whether to update the search indexes for the resaved elements.

--touch

Whether to update the dateUpdated timestamp for the elements.

--type

The type handle(s) of the elements to resave.

--field

The field handle to save Matrix blocks for.

--set

An attribute name that should be set for each of the elements. The value will be determined by --to.

--to

The value that should be set on the --set attribute.

The following value types are supported:

  • An attribute name: --to myCustomField
  • An object template: --to "={myCustomField|lower}"
  • A raw value: --to "=foo bar"
  • A PHP arrow function: --to "fn($element) => $element->callSomething()"
  • An empty value: --to :empty:
--if-empty

Whether the --set attribute should only be set if it doesn’t have a value.

# resave/tags

Re-saves tags.

Options

--queue

Whether the elements should be resaved via a queue job.

--element-id

The ID(s) of the elements to resave.

--uid

The UUID(s) of the elements to resave.

--site

The site handle to save elements from.

--status

The status(es) of elements to resave. Can be set to multiple comma-separated statuses.

--offset

The number of elements to skip.

--limit

The number of elements to resave.

--update-search-index

Whether to update the search indexes for the resaved elements.

--touch

Whether to update the dateUpdated timestamp for the elements.

--group

The group handle(s) to save categories/tags/users from. Can be set to multiple comma-separated groups.

--set

An attribute name that should be set for each of the elements. The value will be determined by --to.

--to

The value that should be set on the --set attribute.

The following value types are supported:

  • An attribute name: --to myCustomField
  • An object template: --to "={myCustomField|lower}"
  • A raw value: --to "=foo bar"
  • A PHP arrow function: --to "fn($element) => $element->callSomething()"
  • An empty value: --to :empty:
--if-empty

Whether the --set attribute should only be set if it doesn’t have a value.

# resave/users

Re-saves users.

Options

--queue

Whether the elements should be resaved via a queue job.

--element-id

The ID(s) of the elements to resave.

--uid

The UUID(s) of the elements to resave.

--site

The site handle to save elements from.

--status

The status(es) of elements to resave. Can be set to multiple comma-separated statuses.

--offset

The number of elements to skip.

--limit

The number of elements to resave.

--update-search-index

Whether to update the search indexes for the resaved elements.

--touch

Whether to update the dateUpdated timestamp for the elements.

--group

The group handle(s) to save categories/tags/users from. Can be set to multiple comma-separated groups.

--set

An attribute name that should be set for each of the elements. The value will be determined by --to.

--to

The value that should be set on the --set attribute.

The following value types are supported:

  • An attribute name: --to myCustomField
  • An object template: --to "={myCustomField|lower}"
  • A raw value: --to "=foo bar"
  • A PHP arrow function: --to "fn($element) => $element->callSomething()"
  • An empty value: --to :empty:
--if-empty

Whether the --set attribute should only be set if it doesn’t have a value.

# serve

# serve

Runs PHP built-in web server.

Parameters

address
address to serve on. Either "host" or "host:port".

Options

--docroot, -t
path or path alias (opens new window) of the directory to serve.
--port, -p
port to serve on.
--router, -r
path or path alias (opens new window) to router script. See https://www.php.net/manual/en/features.commandline.webserver.php

# setup

Craft CMS setup installer.

# setup/app-id

Generates a new application ID and saves it in the .env file.

# setup/db

Alias for setup/db-creds.

Options

--driver
The database driver to use. Either 'mysql' for MySQL or 'pgsql' for PostgreSQL.
--server
The database server name or IP address. Usually 'localhost' or '127.0.0.1'.
--port
The database server port. Defaults to 3306 for MySQL and 5432 for PostgreSQL.
--user
The database username to connect with.
--password
The database password to connect with.
--database
The name of the database to select.
--schema
The schema that Postgres is configured to use by default (PostgreSQL only).
--table-prefix
The table prefix to add to all database tables. This can be no more than 5 characters, and must be all lowercase.

# setup/db-cache-table

Creates a database table for storing DB caches.

# setup/db-creds

Stores new DB connection settings to the .env file.

Options

--driver
The database driver to use. Either 'mysql' for MySQL or 'pgsql' for PostgreSQL.
--server
The database server name or IP address. Usually 'localhost' or '127.0.0.1'.
--port
The database server port. Defaults to 3306 for MySQL and 5432 for PostgreSQL.
--user
The database username to connect with.
--password
The database password to connect with.
--database
The name of the database to select.
--schema
The schema that Postgres is configured to use by default (PostgreSQL only).
--table-prefix
The table prefix to add to all database tables. This can be no more than 5 characters, and must be all lowercase.

# setup

Sets up all the things.

# setup/php-session-table

Creates a database table for storing PHP session information.

# setup/security-key

Generates a new security key and saves it in the .env file.

# setup/welcome

Called from the post-create-project-cmd Composer hook.

# shell

# shell

Runs an interactive shell.

This command requires the yiisoft/yii2-shell (opens new window) package, which you may need to add to your project:

composer require --dev yiisoft/yii2-shell
$ php craft shell
Psy Shell v0.10.4 (PHP 7.4.3 — cli) by Justin Hileman
>>> help
  help       Show a list of commands. Type `help [foo]` for information about [foo].      Alias
  ls         List local, instance or class variables, methods and constants.              Alias
  dump       Dump an object or primitive.
  doc        Read the documentation for an object, class, constant, method or property.   Alias
  show       Show the code for an object, class, constant, method or property.
  wtf        Show the backtrace of the most recent exception.                             Alias
  whereami   Show where you are in the code.
  throw-up   Throw an exception or error out of the Psy Shell.
  timeit     Profiles with a timer.
  trace      Show the current call stack.
  buffer     Show (or clear) the contents of the code input buffer.                       Alias
  clear      Clear the Psy Shell screen.
  edit       Open an external editor. Afterwards, get produced code in input buffer.
  sudo       Evaluate PHP code, bypassing visibility restrictions.
  history    Show the Psy Shell history.                                                  Alias
  exit       End the current session and return to caller.                                Alias

Options

--include
Include file(s) before starting tinker shell.

# tests

# tests/setup

Sets up a test suite for the current project.

Parameters

dst
The folder that the test suite should be generated in. Defaults to the current working directory.

# up

# up

Runs pending migrations and applies pending project config changes.

Options

--force
Whether to perform the action even if a mutex lock could not be acquired.

# update

Updates Craft and plugins.

# update/composer-install

Installs dependencies based on the current composer.json & composer.lock.

# update/info

Displays info about available updates.

# update/update

Updates Craft and/or plugins.

Parameters

handle
The update handle (all, craft, or a plugin handle). You can pass multiple handles separated by spaces, and you can update to a specific version using the syntax <handle>:<version>.

Options

--force, -f
Force the update if allowUpdates is disabled
--backup
Backup the database before updating
--migrate
Run new database migrations after completing the update

# users

Manages user accounts.

# users/activation-url

Generates an activation URL for a pending user.

Parameters

user
The ID, username, or email address of the user account.

# users/create

Creates a user.

Options

--email
The user’s email address.
--username
The user’s username.
--password
The user’s new password.
--admin
Whether the user should be an admin.
--groups
The group handles to assign the created user to.
--group-ids
The group IDs to assign the user to the created user to.

# users/delete

Deletes a user.

Parameters

user
The ID, username, or email address of the user account.

Options

--inheritor
The email or username of the user to inherit content when deleting a user.
--delete-content
Whether to delete the user’s content if no inheritor is specified.
--hard
Whether the user should be hard-deleted immediately, instead of soft-deleted.

# users/impersonate

Generates a URL to impersonate a user.

Parameters

user
The ID, username, or email address of the user account.

# users/list-admins

Lists admin users.

# users/logout-all

Logs all users out of the system.

# users/password-reset-url

Generates a password reset URL for a user.

Parameters

user
The ID, username, or email address of the user account.

# users/set-password

Changes a user’s password.

Parameters

user
The ID, username, or email address of the user account.

Options

--password
The user’s new password.

# users/unlock

Unlocks a user's account.

Parameters

user
The ID, username, or email address of the user account.

# utils/ascii-filenames

# utils/ascii-filenames

Converts all non-ASCII asset filenames to ASCII.

# utils/fix-element-uids

# utils/fix-element-uids

Ensures all elements UIDs are unique.

# utils/prune-provisional-drafts

# utils/prune-provisional-drafts

Prunes provisional drafts for elements that have more than one per user.

Options

--dry-run
Whether this is a dry run.

# utils/prune-revisions

# utils/prune-revisions

Prunes excess element revisions.

Options

--section
The section handle(s) to prune revisions from. Can be set to multiple comma-separated sections.
--max-revisions
The maximum number of revisions an element can have.
--dry-run
Whether this is a dry run.

# utils/repair

Repairs data.

# utils/repair/category-group-structure

Repairs structure data for a category group.

Parameters

handle
The category group handle.

Options

--dry-run
Whether to only do a dry run of the repair process.

# utils/repair/project-config

Repairs double-packed associative arrays in the project config.

Options

--dry-run
Whether to only do a dry run of the repair process.

# utils/repair/section-structure

Repairs structure data for a section.

Parameters

handle
The section handle.

Options

--dry-run
Whether to only do a dry run of the repair process.

# utils/update-usernames

# utils/update-usernames

Updates all users’ usernames to ensure they match their email address.