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
| Flag | Description |
|---|---|
--dbname=NAME | MySQL database name |
--dbuser=USER | MySQL username |
--dbpass=PASS | MySQL password |
Common Optional Flags
| Flag | Default | Description |
|---|---|---|
--dbhost=HOST | localhost | Database host |
--dbprefix=PREFIX | wp_ | Table prefix |
--dbcharset=CHARSET | utf8mb4 | Database character set |
--dbcollate=COLLATE | `` | Database collation |
--locale=LOCALE | en_US | WordPress locale |
--extra-php | — | Append extra PHP to the config (pipe via stdin) |
--skip-salts | — | Skip fetching salts from wordpress.org |
--skip-check | — | Skip DB connection check |
--force | — | Overwrite 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
- Never hardcode credentials in shell scripts — use environment variables or vault secrets.
- Use
--extra-phpto set security constants (DISALLOW_FILE_EDIT,FORCE_SSL_ADMIN) during provisioning. - Use
--forceonly in automation where overwriting an existing config is intentional. - Use
--skip-checkin Docker containers where the DB may not be ready at provisioning time.
Troubleshooting
| Problem | Cause | Fix |
|---|---|---|
Error: wp-config.php already exists | Config present | Add --force to overwrite |
Error: Database connection failed | Wrong DB credentials or host | Test with mysql -u user -p -h host dbname |
| Salts not inserted | Can't reach wordpress.org API | Use --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
wp config get— read and verify config values.wp config set— update values in an existing config.wp core install— run after config creation to install WordPress.