Skip to main content

wp config create

Overview

Generate a wp-config.php file from the command line with database credentials, table prefix, salts, and any extra constants you need — all without manually editing a PHP file. Essential for automated site provisioning, Docker containers, and CI/CD pipelines.

What It Does

wp config create reads the provided credentials and constants, fetches fresh security keys/salts from the wordpress.org secret-key API, and writes a properly formatted wp-config.php to the WordPress root.

Syntax

wp config create --dbname=<db> --dbuser=<user> --dbpass=<pass> [OPTIONS]

Required Options

FlagDescription
--dbname=NAMEMySQL database name
--dbuser=USERMySQL username
--dbpass=PASSMySQL password

Common Optional Flags

FlagDefaultDescription
--dbhost=HOSTlocalhostDatabase host
--dbprefix=PREFIXwp_Table prefix
--dbcharset=CHARSETutf8mb4Database character set
--dbcollate=COLLATE``Database collation
--locale=LOCALEen_USWordPress locale
--extra-phpAppend extra PHP to the config (pipe via stdin)
--skip-saltsSkip fetching salts from wordpress.org
--skip-checkSkip DB connection check
--forceOverwrite an existing wp-config.php

Basic Usage

Minimal config creation

wp config create \
--dbname=my_wp_db \
--dbuser=wp_user \
--dbpass='StrongPass!123'

Custom host and prefix

wp config create \
--dbname=my_wp_db \
--dbuser=wp_user \
--dbpass='StrongPass!123' \
--dbhost=db.internal.example.com \
--dbprefix=blog_

Add extra PHP constants

wp config create \
--dbname=my_wp_db \
--dbuser=wp_user \
--dbpass='StrongPass!123' \
--extra-php <<PHP
define('WP_DEBUG', true);
define('WP_DEBUG_LOG', true);
define('DISALLOW_FILE_EDIT', true);
define('WP_MEMORY_LIMIT', '256M');
PHP

Real-World Scenarios

Scenario 1: Full automated site provisioning

#!/bin/bash
# provision-wp.sh

DB_NAME="wordpress_prod"
DB_USER="wp_prod"
DB_PASS="$(openssl rand -base64 20)"
WP_DIR="/var/www/wordpress"

# Download WordPress
wp core download --path="$WP_DIR"

# Create config
wp config create \
--path="$WP_DIR" \
--dbname="$DB_NAME" \
--dbuser="$DB_USER" \
--dbpass="$DB_PASS" \
--dbhost=localhost \
--extra-php <<PHP
define('DISALLOW_FILE_EDIT', true);
define('WP_AUTO_UPDATE_CORE', 'minor');
define('FORCE_SSL_ADMIN', true);
PHP

# Install WordPress
wp core install \
--path="$WP_DIR" \
--url="https://example.com" \
--title="My Site" \
--admin_user="admin" \
--admin_password="$(openssl rand -base64 16)" \
--admin_email="admin@example.com"

echo "WordPress provisioned at: $WP_DIR"

Scenario 2: Docker container entrypoint

# Dockerfile entrypoint.sh
wp config create \
--dbname="${WORDPRESS_DB_NAME}" \
--dbuser="${WORDPRESS_DB_USER}" \
--dbpass="${WORDPRESS_DB_PASSWORD}" \
--dbhost="${WORDPRESS_DB_HOST}" \
--allow-root \
--force

Scenario 3: Staging clone with different credentials

wp config create \
--dbname=wordpress_staging \
--dbuser=wp_staging \
--dbpass='StagingPass!456' \
--dbhost=staging-db.internal \
--force \
--extra-php <<PHP
define('WP_DEBUG', true);
define('WP_DEBUG_DISPLAY', false);
define('WP_DEBUG_LOG', true);
PHP

Best Practices

  1. Never hardcode credentials in shell scripts — use environment variables or vault secrets.
  2. Use --extra-php to set security constants (DISALLOW_FILE_EDIT, FORCE_SSL_ADMIN) during provisioning.
  3. Use --force only in automation where overwriting an existing config is intentional.
  4. Use --skip-check in Docker containers where the DB may not be ready at provisioning time.

Troubleshooting

ProblemCauseFix
Error: wp-config.php already existsConfig presentAdd --force to overwrite
Error: Database connection failedWrong DB credentials or hostTest with mysql -u user -p -h host dbname
Salts not insertedCan't reach wordpress.org APIUse --skip-salts and add salts manually

Quick Reference

wp config create --dbname=db --dbuser=user --dbpass='pass'
wp config create ... --dbhost=db.internal --dbprefix=mysite_
wp config create ... --force # Overwrite existing
wp config create ... --skip-check # Skip DB connection test
wp config get # Verify after creation

Next Steps