Changing various settings within your wp-config.php file can be done easily with command line text editors like Vim or Nano, but did you know that you can make changes with WP-CLI too? Here's how to do it.
Generating a New Configuration File
Doing a new installation and need to generate a new wp-config.php file? Just run this command (replacing the red text with your database name, user, and password) and one will be generated for you:
pagely-wp config create --dbname=DB_NAME --dbuser=DB_USER --dbpass=DB_PASSWORD
Listing All Configuration Settings
To get a list of all configuration settings within your wp-config.php file, run the following from within your WordPress site's root directory:
pagely-wp config list
Checking If a Setting Exists
Need to see if a setting is defined within your wp-config.php file? Just use this command, replacing SETTING_NAME with the name of your configuration setting:
pagely-wp config has SETTING_NAME
Get a Single Configuration Setting
If you need to check a particular configuration setting, use this command to get it, replacing SETTING_NAME with your desired setting:
pagely-wp config get SETTING_NAME
Defining or Changing a Configuration Setting
Adding or changing a configuration setting in your wp-config.php file is just as simple. Simply run this command from within your WordPress site's root directory, replacing NAME and VALUE with your setting name and value:
pagely-wp config set NAME VALUE
Deleting a Configuration Setting
You can also delete settings from your wp-config.php file with WP-CLI. Here's how to do it.
Note: Always be sure to back up your files before making any changes. Once it's deleted, it's gone.
pagely-wp config delete SETTING_NAME