Wp-config.php settings for security and debugging

The wp-config.php file sits in the WordPress root, in the same folder as wp-admin and wp-content. For security and debugging, a handful of constants is enough: salts, DISALLOW_FILE_EDIT, WP_DEBUG_LOG with on-screen display switched off, a memory limit and file permissions between 400 and 640. Below you will find the exact code and where to put it.
Some settings work anywhere. Others (php.ini, chown, system cron) need root access, which means a VPS.
In brief
- Add every constant above the "That's all, stop editing! Happy publishing." line, after taking a backup copy of the file.
- Safe debugging in production means logging switched on and error display switched off.
- WP_MEMORY_LIMIT can never exceed PHP's memory_limit, and only server access lets you raise that.
- For permissions, the WordPress documentation says 440 or 400. 640 or 600 also work, depending on who owns the PHP process.
- An eight-point checklist sums up the checks to run before going live.
wp-config.php: where to find it and what it does
This is WordPress's configuration file. It holds the database credentials, the security keys and the debug and memory constants. It lives in the root of the installation, for example /var/www/html/, and you can open it over SFTP or SSH (nano, vim).
On installation, it is created from wp-config-sample.php. WordPress will also look for it one level above the root, provided there is no wp-settings.php in that folder.
One rule to remember: all your constants go before the line reading "That's all, stop editing! Happy publishing." After that line, WordPress has already loaded its settings. Take a backup first:
cp wp-config.php wp-config.php.bak
The basics: database settings and table prefix
define( 'DB_NAME', 'wp_site' );
define( 'DB_USER', 'wp_user' );
define( 'DB_PASSWORD', 'long-unique-password' );
define( 'DB_HOST', 'localhost' ); // or 'localhost:/var/run/mysqld/mysqld.sock'
define( 'DB_CHARSET', 'utf8mb4' );
$table_prefix = 'wp_x7k2_';
On a VPS, DB_HOST can point to localhost or to a Unix socket. A custom prefix is only a minor extra: it gets in the way of a few automated scripts but does nothing against SQL injection. The real gain comes from a dedicated database user with limited privileges. Create one rather than reusing the MySQL root account.
Securing WordPress with wp-config.php
There are four levers: salts, hardening constants, file permissions and server-side protection of the file.
Security keys and salts
The eight constants AUTH_KEY, SECURE_AUTH_KEY, LOGGED_IN_KEY, NONCE_KEY and their *_SALT counterparts are used to encrypt session cookies. Generate them with the official WordPress generator or, with WP-CLI:
wp config shuffle-salts
Every user is then logged out. It is the right reflex after a compromise, or after a contractor who had admin access moves on.
Hardening constants
define( 'DISALLOW_FILE_EDIT', true ); // removes the theme/plugin editor from the dashboard
define( 'DISALLOW_FILE_MODS', true ); // also blocks installs and updates from the admin area
define( 'FORCE_SSL_ADMIN', true ); // login and admin over HTTPS only
define( 'WP_ENVIRONMENT_TYPE', 'production' ); // local, development, staging or production
You will want DISALLOW_FILE_EDIT almost every time: a stolen admin account can no longer inject PHP through the editor. DISALLOW_FILE_MODS suits you if your deployments go through Git or WP-CLI, but it also blocks updates from the dashboard. FORCE_SSL_ADMIN assumes a valid certificate. As for WP_ENVIRONMENT_TYPE, available since WordPress 5.5, it lets plugins adapt their behaviour. To go further, see how to access the WordPress admin area and secure it on a VPS.
File permissions and server-side protection (VPS)
The official WordPress documentation recommends 440 or 400 for wp-config.php, so that other users on the server cannot read it. In practice, it all depends on who owns the PHP process:
# The owner is the PHP-FPM pool user
sudo chown www-data:www-data wp-config.php
sudo chmod 400 wp-config.php # or 600 if you edit with that same account
# File managed by another account (deployment), read by PHP through the group
sudo chown deploy:www-data wp-config.php
sudo chmod 640 wp-config.php
The chown command needs root access, which shared hosting does not give you. Three protections come on top, all server-side:
- Move the file one level above the web root: WordPress finds it on its own.
- Block HTTP access if the file stays in the web root.
- Take the secrets out of the file with
getenv(), declaring the variables in the PHP-FPM pool.
# Nginx
location ~* wp-config\.php { deny all; }
# Apache (.htaccess)
<Files wp-config.php>
Require all denied
</Files>
define( 'DB_PASSWORD', getenv( 'WP_DB_PASSWORD' ) );
The rest of the machine matters just as much, so harden the operating system and SSH access as well.
Turning on debug mode without exposing errors
The safe combination: log everything, show nothing to visitors.
define( 'WP_DEBUG', true );
define( 'WP_DEBUG_LOG', true ); // or a path: '/var/log/wordpress/debug.log' (since WP 5.1)
define( 'WP_DEBUG_DISPLAY', false );
@ini_set( 'display_errors', 0 );
// Development only: these slow the site down
// define( 'SCRIPT_DEBUG', true );
// define( 'SAVEQUERIES', true );
The default log is wp-content/debug.log. Unless something blocks it, anyone can read it from a browser, and it can reveal file paths, SQL queries and sometimes personal data. Use a path outside the web root, or deny access to it (location ~* debug\.log$ { deny all; } on Nginx).
On a VPS, follow it live with tail -f wp-content/debug.log. Check the PHP-FPM and Nginx logs too, which catch fatal errors that occur before WordPress loads. Once the problem is fixed, remove these lines or set WP_DEBUG to false.
Raising the WordPress memory limit
define( 'WP_MEMORY_LIMIT', '256M' ); // front end
define( 'WP_MAX_MEMORY_LIMIT', '512M' ); // admin area
According to Elementor, WordPress tries to use 40 MB by default on a single site and 64 MB on multisite. For the admin area, WPZOOM gives a default of 256 MB. Check these values against your own version.
If your setting seems to have no effect, the reason is simple: WordPress cannot go beyond PHP's memory_limit. On shared hosting, that ceiling belongs to the host. On a VPS, you raise it yourself, in php.ini or in the PHP-FPM pool:
; /etc/php/8.3/fpm/pool.d/ (adjust the version)
php_admin_value[memory_limit] = 512M
sudo systemctl reload php8.3-fpm
Then check under Tools > Site Health > Info. On our WordPress VPS plans, KVM virtualisation is strict and there is no resource over-allocation: the RAM you give to PHP is the RAM of your machine.
Other constants worth knowing
define( 'WP_POST_REVISIONS', 5 ); // limits the revisions stored in the database
define( 'AUTOSAVE_INTERVAL', 120 ); // autosave every 120 seconds
define( 'EMPTY_TRASH_DAYS', 14 ); // empties the bin after 14 days
define( 'WP_AUTO_UPDATE_CORE', 'minor' ); // automatic minor updates
define( 'FS_METHOD', 'direct' ); // VPS, if permissions are correct
define( 'WP_HOME', '' ); // useful during a migration
define( 'WP_SITEURL', '' );
define( 'DISABLE_WP_CRON', true ); // requires a real system cron
With DISABLE_WP_CRON, scheduled tasks no longer fire on every page visit. You therefore need to add a system cron job to the site user's crontab (WP-CLI must be installed):
*/5 * * * * cd /var/www/html && wp cron event run --due-now
To edit the file without risking a syntax slip, use wp config set WP_POST_REVISIONS 5 --raw. For updates and cron, our guide to WordPress maintenance on a VPS in 8 checks covers the full routine.
wp-config.php checklist before going live
wp-config.php.bakbackup taken.- Unique salts, regenerated after any incident.
DISALLOW_FILE_EDITset totrue.WP_DEBUG_DISPLAYset tofalse.debug.logprotected, moved outside the web root, or disabled.- Permissions between 400 and 640, depending on who owns the PHP process.
- HTTP access to wp-config.php blocked, or the file kept outside the web root.
WP_MEMORY_LIMITin line with PHP'smemory_limit.
On a VPS, these eight points are easy to tick off, because you control PHP, permissions and cron.
Frequently asked questions
Where is the wp-config.php file in WordPress?
In the root of the installation, in the folder that contains wp-admin and wp-content. It can also sit one level above, if that parent folder has no wp-settings.php. If it is missing, rename wp-config-sample.php.
How do I enable debug mode in wp-config.php without showing errors to visitors?
Set WP_DEBUG to true, WP_DEBUG_LOG to true and WP_DEBUG_DISPLAY to false, along with @ini_set( 'display_errors', 0 );. Errors then go to the log, not the screen. Protect or move that log.
Why is WP_MEMORY_LIMIT not working on my site?
PHP's memory_limit is lower than the value you asked for, and WordPress cannot exceed it. On shared hosting, only the host can change it. On a VPS, edit php.ini or the PHP-FPM pool, reload php-fpm, then check in Site Health.
What permissions (chmod) should I set on wp-config.php?
The WordPress documentation recommends 440 or 400. If the file belongs to the PHP-FPM user, 400 or 600 will work. If it belongs to another account and shares the PHP group, use 640.
Can I move wp-config.php out of the public folder?
Yes, one level above the web root, provided the parent folder contains no wp-settings.php. WordPress finds it on its own, and the web server no longer serves the file. On shared hosting, that parent folder is not always accessible.
What should I do if the site shows a blank page after editing wp-config.php?
Restore the backup: cp wp-config.php.bak wp-config.php. Otherwise, check the syntax with php -l wp-config.php. Look for a missing semicolon, or curly quotes copied from a web page.
Move to a VPS and take control
On shared hosting, you run into a capped memory_limit, permissions you cannot change, and no system cron or WP-CLI. The OmegaCloud WordPress VPS removes those blockers: root SSH access, guaranteed KVM resources, hosting at Telehouse Paris, 1 Tbit/s Anti-DDoS included and 24/7 human support. Snapshots let you roll back after a botched wp-config.php edit.
The plans are currently available for pre-order, with availability announced for 1 November 2026. In the meantime, take a snapshot before every configuration change.