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.
The version of PHP that handles HTTP requests may not be the same as the one that is available directly in your terminal. Some development environments or hosting platforms have specific tools for running console commands—for example, DDEV has a special ddev craft …
command that automatically attaches to the appropriate container before running a command. In this case, you would use ddev craft
instead of php craft
.
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.
The complete list of available commands will include those from any plugins or custom modules you’ve added to your project. The list below represents just those that are present by default in all Craft installations.
# Global Options
All commands support the following options:
--color
- Explicitly enable or disable ANSI coloring in output. When omitted, color will only be used in environments that support it.
--help
- Displays help about the command, rather than running it. Alternative to
php craft help controller/action
. --interactive
- Enable or disable interactive prompts for the command. For use in unattended or automated workflows (like CRON or deployments), consider setting
--interactive=0
. --isolated
- Acquire a mutex lock (opens new window) before running the command to prevent simultaneous execution. Some commands (like
migrate
andproject-config
) have their own internal locking mechanism. A properly configured, centralized mutex driver is required in load-balanced environments—the default file-based driver (prior to Craft 4.6.0) can only prevent concurrent execution on a single machine. --silent-exit-on-exception
- Force a nominal exit code (
0
), even if an exception occurred. Useful when inconsequential failures would otherwise block chained commands in automated environments.
# 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 toutf8
. - collation
- The target collation, which honors
DbConfig::$collation
or defaults toutf8_unicode_ci
.
# db/drop-all-tables
Drops all tables in the database.
Example:
php craft db/drop-all-tables
# db/drop-table-prefix
Drops the database table prefix from all tables.
Parameters
- prefix
- The current table prefix. If omitted, the prefix will be detected automatically.
# db/restore
Restores a database backup.
Example:
php craft db/restore ./my-backup.sql
Parameters
- path
- The path to the database backup file.
Options
- --drop-all-tables
- Whether to drop all preexisting tables in the database prior to restoring the backup.
# elements
Manages elements.
# elements/delete
Deletes an element by its ID.
Parameters
- id
- The element ID to delete.
Options
- --hard
- Whether the element should be hard-deleted.
# elements/restore
Restores an element by its ID.
Parameters
- id
- The element ID to restore.
# entrify
Converts categories, tags, and global sets to entries.
# entrify/categories
Converts categories to entries.
Parameters
- categoryGroup
- The category group handle
Options
- --section
- The section handle that entries should be saved in
- --entry-type
- The entry type handle that entries should have
- --author
- The author username or email that entries should have
# entrify/global-set
Converts a global set to a Single section.
Parameters
- globalSet
- The global set handle
Options
- --section
- The section handle that entries should be saved in
# entrify/tags
Converts tags to entries.
Parameters
- tagGroup
- The tag group handle
Options
- --section
- The section handle that entries should be saved in
- --entry-type
- The entry type handle that entries should have
- --author
- The author username or email that entries should have
# env
Sets or removes environment variables in the .env
file.
# env/remove
Removes an environment variable from the .env
file.
php craft env/remove CRAFT_DEV_MODE
Parameters
name :
# env/set
Sets an environment variable in the .env
file.
php craft env/set CRAFT_DEV_MODE true
Parameters
name :
value :
# env/show
Displays the value of an environment variable, or sets its value if $name contains =
.
php craft env CRAFT_DEV_MODE
php craft env CRAFT_DEV_MODE=true
Parameters
name :
# exec
# exec/exec
Executes a PHP statement and outputs the result.
Parameters
command :
# 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.
# 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.
- --delete-empty-folders
- Whether empty folders should be deleted.
# index-assets/cleanup
Removes all CLI indexing sessions.
# 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.
- --delete-empty-folders
- Whether empty folders should be deleted.
# install
Craft CMS CLI installer.
# install/check
Checks whether Craft is already installed.
# install/craft
Runs the install migration.
Options
- 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 language 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 tovendor/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 isall
, 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
.)
Ifall
, 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
.)
Ifall
, 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. Whenall
, 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 “Retry Duration” general setting can be used to configure a system-wide
Retry-After
header.The
isSystemLive
config setting takes precedence over thesystem.live
project config value, so ifconfig/general.php
setsisSystemLive
totrue
orfalse
theseon
/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 3.0.0
ckeditor CKEditor 2.0.0
commerce Craft Commerce 4.0.0
gatsby-helper Gatsby Helper 2.0.0
Choose a plugin handle to disable: ckeditor
*** disabling ckeditor
*** disabled ckeditor successfully (time: 0.003s)
Parameters
- handle
- The plugin handle (omitted if --all provided).
Options
- --all
- Whether the action should be run for all Composer-installed plugins.
# plugin/enable
Enables a plugin.
$ php craft plugin/enable
The following plugins are disabled:
Handle Name Version
---------- ---------- -------
apple-news Apple News 3.0.0
ckeditor CKEditor 2.0.0
Choose a plugin handle to enable: ckeditor
*** enabling ckeditor
*** enabled ckeditor successfully (time: 0.004s)
Parameters
- handle
- The plugin handle (omitted if --all provided).
Options
- --all
- Whether the action should be run for all Composer-installed plugins.
# plugin/install
Installs a plugin.
$ php craft plugin/install
The following uninstalled plugins are present:
Handle Name Version
------------- -------------- -------
anchors Anchors 3.0.0
apple-news Apple News 3.0.0
ckeditor CKEditor 2.0.0
commerce Craft Commerce 4.0.0
gatsby-helper Gatsby Helper 2.0.0
Choose a plugin handle to install: ckeditor
*** installing ckeditor
*** installed ckeditor successfully (time: 0.496s)
Parameters
- handle
- The plugin handle (omitted if --all provided).
Options
- --all
- Whether the action should be run for all Composer-installed plugins.
# plugin/list
Lists all plugins.
$ php craft plugin/list
Name Handle Package Name Version Installed Enabled
-------------- ------------- ---------------------- ------- --------- -------
Anchors anchors craftcms/anchors 3.0.0 Yes Yes
Apple News apple-news craftcms/apple-news 3.0.0 Yes Yes
CKEditor ckeditor craftcms/ckeditor 2.0.0 Yes Yes
Craft Commerce commerce craftcms/commerce 4.0.0 Yes Yes
Gatsby Helper gatsby-helper craftcms/gatsby-helper 2.0.0 Yes Yes
# plugin/uninstall
Uninstalls a plugin.
$ php craft plugin/uninstall
The following plugins plugins are installed and enabled:
Handle Name Version
------------- -------------- -------
anchors Anchors 3.0.0
apple-news Apple News 3.0.0
ckeditor CKEditor 2.0.0
commerce Craft Commerce 4.0.0
gatsby-helper Gatsby Helper 2.0.0
Choose a plugin handle to uninstall: ckeditor
*** uninstalling ckeditor
*** uninstalled ckeditor successfully (time: 0.496s)
Parameters
- handle
- The plugin handle (omitted if --all provided).
Options
- --force
- Whether the plugin uninstallation should be forced.
- --all
- Whether the action should be run for all Composer-installed plugins.
# project-config
Manages the Project Config.
# project-config/apply
Applies project config file changes.
Options
- --force
- Whether every entry change should be force-applied.
- --quiet
- Whether to reduce the command output.
# project-config/diff
Outputs 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 pull values from the project config YAML files instead of the loaded config.
- --overwrite
- Whether to overwrite an existing export file, if a specific file path is given.
# project-config/get
Outputs a project config value.
Example:
php craft project-config/get system.edition
The “path” syntax used here may be composed of directory and filenames (within your config/project
folder), YAML object keys (including UUIDs for many Craft resources), and integers (referencing numerically-indexed arrays), joined by a dot (.
): path.to.nested.array.0.property
.
Parameters
- path
- The config item path
Options
- --external
- Whether to pull values from the project config YAML files instead of the loaded config.
# project-config/rebuild
Rebuilds the project config.
# project-config/remove
Removes a project config value.
Example:
php craft project-config/remove some.nested.key
This should only be used when the equivalent change is not possible through the control panel or other Craft APIs. By directly modifying project config values, you are bypassing all validation and can easily destabilize configuration.
As with set, removing values only updates the root dateModified
key when using the --update-timestamp
flag. If you do not include this flag, you must run project-config/touch
before changes will be detected or applied in other environments!
Parameters
- path
- The config item path
# project-config/set
Sets a project config value.
Example:
php craft project-config/set some.nested.key
See get for the accepted key formats.
This should only be used when the equivalent change is not possible through the control panel or other Craft APIs. By directly modifying project config values, you are bypassing all validation and can easily destabilize configuration.
Values are updated in the database and in your local YAML files, but the root dateModified
project config property is only touched when using the --update-timestamp
flag. If you do not update the timestamp along with the value, the change may not be detected or applied in other environments!
Parameters
- path
- The config item path
- value
- The config item value as a valid YAML string
Options
- --force
- Whether every entry change should be force-applied.
- --message
- A message describing the changes.
- --update-timestamp
- Whether the
dateModified
value should be updated
# 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
- --job-id
- The job ID to run
- --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/addresses
Re-saves user addresses.
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 fetch 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.- --owner-id
Comma-separated list of owner element IDs.
- --country-code
Comma-separated list of country codes.
- --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:
- An attribute name:
- --if-empty
Whether the
--set
attribute should only be set if it doesn’t have a value.- --if-invalid
Whether the
--set
attribute should only be set if the current value doesn’t validate.
# 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 fetch 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:
- An attribute name:
- --if-empty
Whether the
--set
attribute should only be set if it doesn’t have a value.- --if-invalid
Whether the
--set
attribute should only be set if the current value doesn’t validate.
# 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 fetch 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:
- An attribute name:
- --if-empty
Whether the
--set
attribute should only be set if it doesn’t have a value.- --if-invalid
Whether the
--set
attribute should only be set if the current value doesn’t validate.
# 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 fetch elements from.
- --propagate-to
Comma-separated site handles to propagate entries to.
When this is set, the entry will only be saved for this site.
- --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.
- --set-enabled-for-site
The site-enabled status that should be set on the entry, for the site it’s initially being saved/propagated 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:
- An attribute name:
- --if-empty
Whether the
--set
attribute should only be set if it doesn’t have a value.- --if-invalid
Whether the
--set
attribute should only be set if the current value doesn’t validate.
# 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 fetch 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.
- --owner-id
Comma-separated list of owner element IDs.
- --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:
- An attribute name:
- --if-empty
Whether the
--set
attribute should only be set if it doesn’t have a value.- --if-invalid
Whether the
--set
attribute should only be set if the current value doesn’t validate.
# 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 fetch 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:
- An attribute name:
- --if-empty
Whether the
--set
attribute should only be set if it doesn’t have a value.- --if-invalid
Whether the
--set
attribute should only be set if the current value doesn’t validate.
# 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 fetch 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:
- An attribute name:
- --if-empty
Whether the
--set
attribute should only be set if it doesn’t have a value.- --if-invalid
Whether the
--set
attribute should only be set if the current value doesn’t validate.
# sections
Manages sections.
# sections/create
Creates a section.
Options
- --name
- The section name.
- --handle
- The section handle.
- --type
- The section type (single, channel, or structure).
- --no-versioning
- Whether to disable versioning for the section.
- --uri-format
- The entry URI format to set for each site.
- --template
- The template to load when an entry’s URL is requested.
- --from-category-group
- The category group handle to model the section from.
- --from-tag-group
- The tag group handle to model the section from.
- --from-global-set
- The global set handle to model the section from.
# sections/delete
Deletes a section.
Parameters
- handle
- The section handle
# 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.
--router, -r :
- --port, -p
- port to serve on.
# setup
Craft CMS setup installer.
# setup/app-id
Generates a new application ID and saves it in the .env
file.
# setup/cloud
Prepares the Craft install to be deployed to Craft Cloud.
# 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.
This is an interactive wrapper for the setup/app-id
, setup/security-key
, setup/db-creds
,
and install
commands, each of which support being run non-interactively.
# setup/keys
Generates an application ID and security key (if they don’t exist), and saves them in the .env
file.
# setup/message-tables
Creates database tables for storing message translations. (EXPERIMENTAL!)
# 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.12 (PHP 8.0.3 — cli) by Justin Hileman
>>> help
help Show a list of commands. Type `help [foo]` for information about [foo]. Aliases: ?
ls List local, instance or class variables, methods and constants. Aliases: dir
dump Dump an object or primitive.
doc Read the documentation for an object, class, constant, method or property. Aliases: rtfm, m
show Show the code for an object, class, constant, method or property.
wtf Show the backtrace of the most recent exception. Aliases: last-ex
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. Aliases: buf
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. Aliases: hist
exit End the current session and return to caller. Aliases: quit, q
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
- --no-backup
- Skip backing up the database.
- --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
- --with-expired
Whether to update expired licenses.
NOTE: This will result in “License purchase required” messages in the control panel on public domains, until the licenses have been renewed.
- --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
- 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/fix-field-layout-uids
# utils/fix-field-layout-uids
Fixes any duplicate UUIDs found within field layout components in the project config.
# utils/prune-orphaned-matrix-blocks
# utils/prune-orphaned-matrix-blocks
Prunes orphaned Matrix blocks for each site.
# 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.