You inherit a production WordPress install from a previous agency. The site has been live for three years. You open wp-config.php and find database credentials in plain text, no DISALLOW_FILE_EDIT, no SSL constants, WP_DEBUG set to true, salts that look like they came from the install wizard in 2022 — and an admin user named admin. None of this is uncommon. Most of it is also one search-engine-result away from being on a public Wayback Machine snapshot if the file ever leaked through a misconfigured backup.
What’s happening
wp-config.php is the only file in a WordPress tree that mixes secrets, runtime behaviour, and security policy in a single PHP file that the web server parses on every request. WordPress core respects roughly 80 constants defined there, but only seven of them actually move the needle on attack surface in production. The defaults assume a developer running locally, not an internet-exposed system.
The three that matter most for blast radius:
DISALLOW_FILE_EDITremoves the Plugin Editor and Theme Editor from wp-admin. Without it, any compromised admin account can drop PHP into a theme file and get RCE without ever touching the filesystem.FORCE_SSL_ADMINrewrites admin URLs to HTTPS and refuses to set the auth cookie over plain HTTP. Without it, login cookies leak on any network that can sniff port 80, including the next coffee shop the marketing director works from.AUTOMATIC_UPDATER_DISABLEDcontrols whether core auto-updates run unattended. The right answer depends on who watches the deploy — auto-updates are a defensible default for sites with no operator on call, dangerous for sites where the deploy pipeline expects to control which version ships.
Then secrets. Hardcoding DB_PASSWORD and the eight salts (AUTH_KEY, SECURE_AUTH_KEY, LOGGED_IN_KEY, NONCE_KEY, and their _SALT siblings) inside wp-config.php works until the file ends up in a backup tarball, a Git history, or a developer’s laptop. Environment variables — read via getenv() and set at the PHP-FPM or web-server level — keep secrets out of the file that gets committed and copied.
How to verify
Audit an existing install with a single WP-CLI loop:
cd /home/<account>/public_html
# 1. List which hardening constants are set and to what
for c in DISALLOW_FILE_EDIT DISALLOW_FILE_MODS FORCE_SSL_ADMIN \
WP_AUTO_UPDATE_CORE AUTOMATIC_UPDATER_DISABLED \
WP_DEBUG WP_DEBUG_DISPLAY WP_DEBUG_LOG \
WP_POST_REVISIONS EMPTY_TRASH_DAYS; do
printf "%-30s = " "$c"
wp config get "$c" 2>/dev/null || echo "<not set>"
done
# 2. Confirm DB password is not literal in the file
grep -E "define\(\s*['\"]DB_PASSWORD['\"]" wp-config.php
# 3. Check salt age — if all eight strings look default, they were never rotated
grep -E "(AUTH_KEY|SECURE_AUTH_KEY|LOGGED_IN_KEY|NONCE_KEY)" wp-config.php | head -8
If DB_PASSWORD line ends with anything other than getenv(...), the secret is in the file. If salts contain the literal string put your unique phrase here, the wizard was never completed.
To confirm FORCE_SSL_ADMIN is doing its job, hit the login page over plain HTTP and watch what happens to the Set-Cookie header:
curl -sI http://example.com/wp-login.php | grep -iE "location|set-cookie"
The expected output is a 301 to https:// with no auth cookie set.
The fix
The minimum production block — drop this above the That's all, stop editing! line:
// --- Secrets via env vars (set in PHP-FPM pool config or systemd unit) ---
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') ?: 'localhost' );
// --- Salts: pulled from env, rotated independently of code deploys ---
define( 'AUTH_KEY', getenv('WP_AUTH_KEY') );
define( 'SECURE_AUTH_KEY', getenv('WP_SECURE_AUTH_KEY') );
define( 'LOGGED_IN_KEY', getenv('WP_LOGGED_IN_KEY') );
define( 'NONCE_KEY', getenv('WP_NONCE_KEY') );
define( 'AUTH_SALT', getenv('WP_AUTH_SALT') );
define( 'SECURE_AUTH_SALT', getenv('WP_SECURE_AUTH_SALT') );
define( 'LOGGED_IN_SALT', getenv('WP_LOGGED_IN_SALT') );
define( 'NONCE_SALT', getenv('WP_NONCE_SALT') );
// --- Lock down editor + filesystem writes from wp-admin ---
define( 'DISALLOW_FILE_EDIT', true ); // removes Plugin/Theme Editor
define( 'DISALLOW_FILE_MODS', true ); // blocks all plugin/theme install/upgrade from UI
// --- Force HTTPS for the admin surface ---
define( 'FORCE_SSL_ADMIN', true );
// --- Updates: operator-controlled, not automatic ---
define( 'AUTOMATIC_UPDATER_DISABLED', true );
define( 'WP_AUTO_UPDATE_CORE', false );
// --- Logging: never display, always write to file outside webroot ---
define( 'WP_DEBUG', false );
define( 'WP_DEBUG_DISPLAY', false );
define( 'WP_DEBUG_LOG', '/var/log/wordpress/debug.log' );
@ini_set( 'display_errors', 0 );
// --- Tame post bloat ---
define( 'WP_POST_REVISIONS', 5 );
define( 'EMPTY_TRASH_DAYS', 14 );
define( 'AUTOSAVE_INTERVAL', 120 );
// --- Optional: trust proxy headers if behind a load balancer ---
if ( isset( $_SERVER['HTTP_X_FORWARDED_PROTO'] )
&& $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https' ) {
$_SERVER['HTTPS'] = 'on';
}
Then set the env vars at the PHP-FPM pool level so the values never appear in the codebase:
; /etc/php-fpm.d/example-com.conf
env[WP_DB_NAME] = "acme_wp"
env[WP_DB_USER] = "acme_wp_app"
env[WP_DB_PASSWORD] = "redacted-at-deploy-time"
env[WP_DB_HOST] = "db.internal:3306"
env[WP_AUTH_KEY] = "..."
env[WP_SECURE_AUTH_KEY] = "..."
; ...remaining six salts
A note on DISALLOW_FILE_MODS: this is stricter than DISALLOW_FILE_EDIT — it disables the plugin and theme install/update UI entirely. On managed environments where deploys go through Git and CI, that’s the right setting. On environments where the customer’s marketing team installs plugins through wp-admin, ship DISALLOW_FILE_EDIT only.
Verify after change:
wp config get DISALLOW_FILE_EDIT # → 1
wp config get FORCE_SSL_ADMIN # → 1
wp config get AUTOMATIC_UPDATER_DISABLED # → 1
wp option get siteurl # → https://...
Stack Harbor ships a hardened wp-config.php baseline as part of Enterprise WordPress operations, with env-var secret handling at the PHP-FPM layer and per-environment salts. If you’re inheriting an install and want an audit before the next deploy, start with a discovery call.