wp configphpnew
wp‑config.php New: The Complete Guide to Modern WordPress Configuration
Key Takeaways
- Understanding the differences between legacy and the new
wp-config.phpstructure. - Step‑by‑step checklist to migrate safely without downtime.
- Best‑in‑class security settings (salts, keys, file permissions, and environment variables).
- Performance tweaks that reduce DB overhead and improve load times.
- Answers to the three most common questions about the new configuration file.
Problem‑Solver Q&A Architecture
Why does my site break after updating wp‑config.php?
Most breakages stem from one of three issues:
- Syntax errors: Missing commas, unmatched quotes, or stray whitespace before
/* That's all, stop editing! */. - Incorrect constant names: The new file uses
DB_HOST,DB_USER,DB_PASSWORD, andDB_NAMEexactly as shown. Typos will cause a fatal error. - File permission problems: The file must be readable by the web server (typically
640or600) but not writable by the public.
How can I keep my credentials out of version control?
Use environment variables or a separate .env file and reference them in wp-config.php:
define( 'DB_NAME', getenv('WP_DB_NAME') );
define( 'DB_USER', getenv('WP_DB_USER') );
define( 'DB_PASSWORD', getenv('WP_DB_PASSWORD') );
define( 'DB_HOST', getenv('WP_DB_HOST') );
Then add the .env file to .gitignore. This approach is recommended for any CI/CD pipeline.
What are the essential security constants I should add?
Beyond the default authentication salts, the new best practice list includes:
DISALLOW_FILE_EDIT– disables the theme/plugin editor.DISALLOW_FILE_MODS– blocks plugin/theme updates from the dashboard (useful on locked production servers).FORCE_SSL_ADMIN– forces admin traffic over HTTPS.WP_AUTO_UPDATE_CORE– controls automatic core updates.
Legacy vs. New wp-config.php Settings
| Aspect | Legacy (pre‑5.5) | New (5.5+ recommended) |
|---|---|---|
| Database credentials | Hard‑coded strings | Environment variables or WP_ENV driven constants |
| Authentication salts | Manually generated once | Auto‑rotate via WP_SALT plugin or CI script |
| File permissions | Often 644 |
Recommended 640 (owner) / 600 (shared host) |
| Debug mode | define('WP_DEBUG', false); only |
Full debug suite: WP_DEBUG_DISPLAY, WP_DEBUG_LOG, SCRIPT_DEBUG |
| Multisite constants | Optional, scattered | Grouped under /* Multisite */ block for clarity |
Migration Checklist – From Old to New wp-config.php
- Backup the current
wp-config.phpand the entire site. - Create a staging copy of the site to test changes.
- Replace hard‑coded credentials with
getenv()calls or a secure.envfile. - Generate fresh authentication salts using WordPress.org secret‑key API.
- Add the recommended security constants (
DISALLOW_FILE_EDIT,FORCE_SSL_ADMIN, etc.). - Set file permissions to
640(owner) and ensure the web‑server user can read the file. - Enable
WP_DEBUGonly on staging; keep it disabled on production. - Test site functionality: login, admin dashboard, front‑end, and any custom plugins that read config values.
- Deploy to production and monitor error logs for 24 hours.
- Document the new configuration in a README for future developers.
Frequently Asked Questions
- Can I keep the old wp-config.php file and create a new one?
- Yes. WordPress will load the file named
wp-config.phpin the root directory. You can keep a backup namedwp-config-old.phpfor reference, but never place two active config files in the same directory. - Do I need to update the
ABSPATHconstant when moving wp-config.php? - No.
ABSPATHis automatically set by WordPress based on the location ofwp-config.php. If you relocate the file outside the root (a recommended hardening step), you must defineABSPATHmanually before requiringwp-settings.php. - What is the best way to version‑control wp-config.php?
- Store a template file (e.g.,
wp-config.sample.php) with placeholders for secrets. Keep the realwp-config.phpout of the repository and generate it during deployment using CI variables or a provisioning script.