wp config

Generates and reads the wp-config.php file.

Subcommands

Command Description
wp config create Generates a wp-config.php file.
wp config delete Deletes a specific constant or variable from the wp-config.php file.
wp config edit Launches system editor to edit the wp-config.php file.
wp config get Gets the value of a specific constant or variable defined in wp-config.php file.
wp config has Checks whether a specific constant or variable exists in the wp-config.php file.
wp config is-true Determines whether value of a specific defined constant or variable is truthy.
wp config list Lists variables, constants, and file includes defined in wp-config.php file.
wp config path Gets the path to wp-config.php file.
wp config set Sets the value of a specific constant or variable defined in wp-config.php file.
wp config shuffle-salts Refreshes the salts defined in the wp-config.php file.

Examples

# Create standard wp-config.php file.
$ wp config create --dbname=testing --dbuser=wp --dbpass=securepswd --locale=ro_RO
Success: Generated 'wp-config.php' file.

# List constants and variables defined in wp-config.php file.
$ wp config list
+------------------+------------------------------------------------------------------+----------+
| key              | value                                                            | type     |
+------------------+------------------------------------------------------------------+----------+
| table_prefix     | wp_                                                              | variable |
| DB_NAME          | wp_cli_test                                                      | constant |
| DB_USER          | root                                                             | constant |
| DB_PASSWORD      | root                                                             | constant |
+------------------+------------------------------------------------------------------+----------+

# Get wp-config.php file path.
$ wp config path
/home/person/htdocs/project/wp-config.php

# Get the table_prefix as defined in wp-config.php file.
$ wp config get table_prefix
wp_

# Set the WP_DEBUG constant to true.
$ wp config set WP_DEBUG true --raw
Success: Updated the constant 'WP_DEBUG' in the 'wp-config.php' file with the raw value 'true'.

# Delete the COOKIE_DOMAIN constant from the wp-config.php file.
$ wp config delete COOKIE_DOMAIN
Success: Deleted the constant 'COOKIE_DOMAIN' from the 'wp-config.php' file.

# Launch system editor to edit wp-config.php file.
$ wp config edit

# Check whether the DB_PASSWORD constant exists in the wp-config.php file.
$ wp config has DB_PASSWORD
$ echo $?
0

# Assert if MULTISITE is true.
$ wp config is-true MULTISITE
$ echo $?
0

# Get new salts for your wp-config.php file.
$ wp config shuffle-salts
Success: Shuffled the salt keys.

wp config create

Generates a wp-config.php file. Creates a new wp-config.php with database constants, and verifies that the database constants are correct.

Synopsis

wp config create --dbname=<dbname> --dbuser=<dbuser> [--dbpass=<dbpass>] [--dbhost=<dbhost>] [--dbprefix=<dbprefix>] [--dbcharset=<dbcharset>] [--dbcollate=<dbcollate>] [--locale=<locale>] [--extra-php] [--skip-salts] [--skip-check] [--force] [--config-file=<path>] [--insecure]

Parameters

Parameter Description
--dbname=<dbname> Set the database name.
--dbuser=<dbuser> Set the database user.
[--dbpass=<dbpass>] Set the database user password.
[--dbhost=<dbhost>] Set the database host. Default: localhost
[--dbprefix=<dbprefix>] Set the database table prefix. Default: wp_
[--dbcharset=<dbcharset>] Set the database charset. Default: utf8
[--dbcollate=<dbcollate>] Set the database collation. Default: empty
[--locale=<locale>] Set the WPLANG constant. Defaults to $wp_local_package variable.
[--extra-php] If set, the command copies additional PHP code into wp-config.php from STDIN.
[--skip-salts] If set, keys and salts won’t be generated, but should instead be passed via --extra-php.
[--skip-check] If set, the database connection is not checked.
[--force] Overwrites existing files, if present.
[--config-file=<path>] Specify the file path to the config file to be created.
[--insecure] Retry API download without certificate validation if TLS handshake fails.

Examples

# Standard wp-config.php file
$ wp config create --dbname=testing --dbuser=wp --dbpass=securepswd --locale=ro_RO
Success: Generated 'wp-config.php' file.

# Enable WP_DEBUG and WP_DEBUG_LOG
$ wp config create --dbname=testing --dbuser=wp --dbpass=securepswd --extra-php <<PHP
define( 'WP_DEBUG', true );
define( 'WP_DEBUG_LOG', true );
PHP
Success: Generated 'wp-config.php' file.

# Avoid disclosing password to bash history by reading from password.txt
$ wp config create --dbname=testing --dbuser=wp --prompt=dbpass < password.txt
Success: Generated 'wp-config.php' file.

wp config delete

Deletes a specific constant or variable from the wp-config.php file.

Synopsis

wp config delete <name> [--type=<type>] [--config-file=<path>]

Parameters

Parameter Description
<name> Name of the wp-config.php constant or variable.
[--type=<type>] Type of the config value to delete. Default: all. Options: constant, variable, all
[--config-file=<path>] Specify the file path to the config file to be modified.

Examples

$ wp config delete COOKIE_DOMAIN
Success: Deleted the constant 'COOKIE_DOMAIN' from the 'wp-config.php' file.

wp config edit

Launches system editor to edit the wp-config.php file.

Synopsis

wp config edit [--config-file=<path>]

Parameters

Parameter Description
[--config-file=<path>] Specify the file path to the config file to be edited.

Examples

# Launch system editor to edit wp-config.php file
$ wp config edit

# Edit wp-config.php file in a specific editor
$ EDITOR=vim wp config edit

wp config get

Gets the value of a specific constant or variable defined in wp-config.php file.

Synopsis

wp config get <name> [--type=<type>] [--format=<format>] [--config-file=<path>]

Parameters

Parameter Description
<name> Name of the wp-config.php constant or variable.
[--type=<type>] Type of config value to retrieve. Default: all. Options: constant, variable, all
[--format=<format>] Get value in a particular format. Default: var_export. Options: var_export, json, yaml, dotenv
[--config-file=<path>] Specify the file path to the config file to be read.

Examples

$ wp config get table_prefix
wp_

wp config has

Checks whether a specific constant or variable exists in the wp-config.php file.

Synopsis

wp config has <name> [--type=<type>] [--config-file=<path>]

Parameters

Parameter Description
<name> Name of the wp-config.php constant or variable.
[--type=<type>] Type of the config value to set. Default: all. Options: constant, variable, all
[--config-file=<path>] Specify the file path to the config file to be checked.

Examples

$ wp config has DB_PASSWORD

wp config is-true

Determines whether value of a specific defined constant or variable is truthy.

This determination is made by evaluating the retrieved value via boolval().

Synopsis

wp config is-true <name> [--type=<type>] [--config-file=<path>]

Parameters

Parameter Description
<name> Name of the wp-config.php constant or variable.
[--type=<type>] Type of config value to retrieve. Default: all. Options: constant, variable, all
[--config-file=<path>] Specify the file path to the config file to be read.

Examples

# Assert if MULTISITE is true
$ wp config is-true MULTISITE
$ echo $?
0

wp config list

Lists variables, constants, and file includes defined in wp-config.php file.

Synopsis

wp config list [<filter>...] [--fields=<fields>] [--format=<format>] [--strict] [--config-file=<path>]

Parameters

Parameter Description
[<filter>...] Name or partial name to filter the list by.
[--fields=<fields>] Limit the output to specific fields. Defaults to all fields.
[--format=<format>] Render output in a particular format. Default: table. Options: table, csv, json, yaml, dotenv
[--strict] Enforce strict matching when a filter is provided.
[--config-file=<path>] Specify the file path to the config file to be read.

Examples

# List constants and variables defined in wp-config.php file.
$ wp config list
+------------------+------------------------------------------------------------------+----------+
| key              | value                                                            | type     |
+------------------+------------------------------------------------------------------+----------+
| table_prefix     | wp_                                                              | variable |
| DB_NAME          | wp_cli_test                                                      | constant |
| DB_USER          | root                                                             | constant |
| DB_PASSWORD      | root                                                             | constant |
+------------------+------------------------------------------------------------------+----------+

# List only database user and password from wp-config.php file.
$ wp config list DB_USER DB_PASSWORD --strict

# List all salts from wp-config.php file.
$ wp config list _SALT

wp config path

Gets the path to wp-config.php file.

Synopsis

wp config path

Examples

$ wp config path
/home/person/htdocs/project/wp-config.php

wp config set

Sets the value of a specific constant or variable defined in wp-config.php file.

Synopsis

wp config set <name> <value> [--add] [--raw] [--anchor=<anchor>] [--placement=<placement>] [--separator=<separator>] [--type=<type>] [--config-file=<path>]

Parameters

Parameter Description
<name> Name of the wp-config.php constant or variable.
<value> Value to set the wp-config.php constant or variable to.
[--add] Add the value if it doesn’t exist yet. This is the default behavior.
[--raw] Place the value into the wp-config.php file as is, instead of as a quoted string.
[--anchor=<anchor>] Anchor string where additions of new values are anchored around. Defaults to "/* That’s all, stop editing!".
[--placement=<placement>] Where to place the new values in relation to the anchor string. Default: before. Options: before, after
[--separator=<separator>] Separator string to put between an added value and its anchor string.
[--type=<type>] Type of the config value to set. Default: all. Options: constant, variable, all
[--config-file=<path>] Specify the file path to the config file to be modified.

Examples

$ wp config set WP_DEBUG true --raw
Success: Updated the constant 'WP_DEBUG' in the 'wp-config.php' file with the raw value 'true'.

wp config shuffle-salts

Refreshes the salts defined in the wp-config.php file.

Synopsis

wp config shuffle-salts [<keys>...] [--force] [--config-file=<path>] [--insecure]

Parameters

Parameter Description
[<keys>...] One or more keys to shuffle. If none are provided, this falls back to the default WordPress Core salt keys.
[--force] If an unknown key is requested to be shuffled, add it instead of throwing a warning.
[--config-file=<path>] Specify the file path to the config file to be modified.
[--insecure] Retry API download without certificate validation if TLS handshake fails.

Examples

# Get new salts for your wp-config.php file
$ wp config shuffle-salts
Success: Shuffled the salt keys.

# Add a cache key salt to the wp-config.php file
$ wp config shuffle-salts WP_CACHE_KEY_SALT --force
Success: Shuffled the salt keys.