New 24/7 monitoring and daily cloud backups now included in every Shield Pro plan.

wp-config

How to secure wp-config.php

wp-config.php holds database credentials and security keys. If attackers read it, they own your site. This tutorial hardens wp-config location, permissions, and security constants without breaking updates.

Time: 20-40 minutes Level: Intermediate

What this problem looks like

wp-config.php is the crown jewels of a WordPress install. Hardening combines file location, chmod, server deny rules, and constants that reduce attack surface in admin.

Some hosts already place wp-config outside public_html. Check before duplicating effort. Never commit wp-config.php to Git or paste it into support tickets.

Step 1: Add recommended security constants

Paste above the stop editing line in wp-config.php on production sites:

php
define( 'DISALLOW_FILE_EDIT', true );
define( 'WP_DEBUG', false );
define( 'WP_DEBUG_LOG', false );
define( 'WP_DEBUG_DISPLAY', false );
DISALLOW_FILE_EDIT removes Theme and Plugin editors from wp-admin. Edit files via SFTP instead so typos do not whitescreen production.

Step 2: Move wp-config.php above web root (optional)

On VPS and some shared hosts, move wp-config.php one folder above public_html. WordPress searches parent directories automatically. Update paths inside the file if you reference absolute directories.

Step 3: Block HTTP access to wp-config.php

If the file must stay in web root, deny browser access in .htaccess:

apache
<Files wp-config.php>
order allow,deny
deny from all
</Files>

Step 4: Set restrictive permissions

Try chmod 440 on wp-config.php. If the site fails to load, use 600 or 644 per host documentation. Ownership should be the web server user, not world-readable.

bash
chmod 440 wp-config.php

Step 5: Rotate keys and limit credentials exposure

Use unique database passwords and rotate AUTH keys after any breach. Store SFTP and database credentials in a password manager or BugShield Vault, not in email or Slack.

When to stop DIY and hire help

Misconfigured wp-config hardening can whitescreen production or block legitimate updates. BugShield secures WordPress configuration at a confirmed price with rollback-safe changes.

FAQs

Does DISALLOW_FILE_EDIT break page builders?

No. It only removes the built-in theme and plugin code editors from wp-admin. Builders and SFTP still work.

Can attackers still read wp-config with 644 permissions?

644 is world-readable on some shared hosts. Tighten to 440 or move the file above web root when possible.

Should I put database passwords in environment variables?

Advanced setups use env vars in wp-config.php. Most UK small business hosts use standard defines. Follow host docs.

Is wp-config.php backup safe in Dropbox?

No. Encrypted password managers or BugShield Vault are appropriate for credential storage.

Rather someone else fixed it?

Request a fix at a confirmed price. Named UK developer, secure Vault, direct chat.

Request a Fix