Skip to main content

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

FlagDescription
--dbname=NAMEMySQL database name
--dbuser=USERMySQL database username

Options

FlagDefaultDescription
--dbpass=PASS(empty)Database password
--dbhost=HOSTlocalhostDatabase host (host:port or socket path)
--dbprefix=PREFIXwp_Table prefix — change for security
--dbcharset=CHARSETutf8mb4Database charset
--dbcollate=COLLATE(empty)Database collation
--locale=LOCALEen_USWordPress locale
--extra-phpRead extra PHP from STDIN and append to config
--skip-saltsDo not add authentication salts
--skip-checkSkip the DB connection check
--forceOverwrite an existing wp-config.php
--config-file=PATHSave to a custom path instead of CWD
--insecureSkip 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

  1. Always change the table prefix — never use the default wp_ in production.
  2. Never hardcode passwords in scripts — use environment variables like $DB_PASS.
  3. Exclude wp-config.php from version control (.gitignore).
  4. Use --extra-php to inject debug or performance constants, not secrets.
  5. Run wp config list after creation to verify all values are correct.

Troubleshooting

ProblemCauseFix
Error: The 'wp-config.php' file already existsFile already presentAdd --force to overwrite
DB connection fails after creationWrong credentials or hostCheck credentials and use --dbhost=127.0.0.1
Salts not fetchedNo internet / SSL issueUse --insecure or --skip-salts then add salts manually
File permissions deniedWP-CLI user cannot writesudo 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