wp config create
Overview
Create a fresh wp-config.php file from the command line. Replaces the five-minute install wizard step and makes WordPress provisioning scriptable and repeatable.
What It Does
wp config create generates a wp-config.php file in the current WordPress root directory. It accepts database credentials, a custom table prefix, locale settings, and inline PHP to inject at creation time — no manual file editing required.
Syntax
wp config create --dbname=<dbname> --dbuser=<dbuser> [--dbpass=<dbpass>] [OPTIONS]
Required Options
| Flag | Description |
|---|---|
--dbname=NAME | MySQL database name |
--dbuser=USER | MySQL database username |
Options
| Flag | Default | Description |
|---|---|---|
--dbpass=PASS | (empty) | Database password |
--dbhost=HOST | localhost | Database host (host:port or socket path) |
--dbprefix=PREFIX | wp_ | Table prefix — change for security |
--dbcharset=CHARSET | utf8mb4 | Database charset |
--dbcollate=COLLATE | (empty) | Database collation |
--locale=LOCALE | en_US | WordPress locale |
--extra-php | — | Read extra PHP from STDIN and append to config |
--skip-salts | — | Do not add authentication salts |
--skip-check | — | Skip the DB connection check |
--force | — | Overwrite an existing wp-config.php |
--config-file=PATH | — | Save to a custom path instead of CWD |
--insecure | — | Skip SSL verification when fetching salts |
Basic Usage
Minimal config (local dev)
wp config create --dbname=mydb --dbuser=root --dbpass=secret
Custom host and prefix
wp config create \
--dbname=wpdb \
--dbuser=wpuser \
--dbpass=StrongPass1! \
--dbhost=127.0.0.1:3306 \
--dbprefix=shop_
Skip DB check (DB not ready yet)
wp config create --dbname=wpdb --dbuser=wpuser --dbpass=secret --skip-check
When to use --skip-check
Use --skip-check only when the database is intentionally not reachable yet (e.g., early Docker provisioning). Always validate connectivity before running wp core install.
Overwrite an existing config
wp config create --dbname=newdb --dbuser=newuser --dbpass=newpass --force
Inject constants at creation time
wp config create --dbname=wpdb --dbuser=wpuser --dbpass=secret --extra-php <<PHP
define( 'WP_DEBUG', true );
define( 'WP_DEBUG_LOG', true );
define( 'WP_MEMORY_LIMIT', '256M' );
PHP
Extra PHP is live code
Everything passed via --extra-php runs in WordPress on every request. Keep it minimal, review it, and never inject secrets directly.
Expected Output
Success: Generated 'wp-config.php' file.
If the file already exists without --force:
Error: The 'wp-config.php' file already exists.
Real-World Scenarios
Scenario 1: Automated server provisioning script
#!/bin/bash
wp core download --locale=en_US
wp config create \
--dbname="${DB_NAME}" \
--dbuser="${DB_USER}" \
--dbpass="${DB_PASS}" \
--dbhost="${DB_HOST}" \
--dbprefix="${DB_PREFIX}" \
--skip-check
wp db create
wp core install \
--url="${SITE_URL}" \
--title="${SITE_TITLE}" \
--admin_user="${ADMIN_USER}" \
--admin_password="${ADMIN_PASS}" \
--admin_email="${ADMIN_EMAIL}"
Scenario 2: Multi-environment config with different prefixes
# Production
wp config create --dbname=prod_db --dbuser=prod_user --dbpass=prod_pass --dbprefix=prod_
# Staging
wp config create --dbname=stag_db --dbuser=stag_user --dbpass=stag_pass --dbprefix=stag_ --force
Best Practices
- Always change the table prefix — never use the default
wp_in production. - Never hardcode passwords in scripts — use environment variables like
$DB_PASS. - Exclude
wp-config.phpfrom version control (.gitignore). - Use
--extra-phpto inject debug or performance constants, not secrets. - Run
wp config listafter creation to verify all values are correct.
Troubleshooting
| Problem | Cause | Fix |
|---|---|---|
Error: The 'wp-config.php' file already exists | File already present | Add --force to overwrite |
| DB connection fails after creation | Wrong credentials or host | Check credentials and use --dbhost=127.0.0.1 |
| Salts not fetched | No internet / SSL issue | Use --insecure or --skip-salts then add salts manually |
| File permissions denied | WP-CLI user cannot write | sudo chown or run as correct user |
Quick Reference
wp config create --dbname=mydb --dbuser=root --dbpass=secret
wp config create --dbname=mydb --dbuser=root --dbpass=secret --dbprefix=app_
wp config create --dbname=mydb --dbuser=root --dbpass=secret --skip-check
wp config create --dbname=mydb --dbuser=root --dbpass=secret --force
Next Steps
wp config list— verify all values after creation.wp config set— add or update constants post-creation.wp config shuffle-salts— rotate authentication salts.- Core Commands — proceed to
wp core install.