On this page
This guide is a complete reference for the file that beginners fear and professionals underestimate. We'll start with the basics — what the file is, where it comes from and when it is read in the WordPress loading cycle — then dissect its contents line by line, then go through every practical constant you will actually need: database details, the table prefix, security keys, debug mode, disabling the file editor, forcing HTTPS for the dashboard, the memory limit, revisions and autosave, site URLs, and disabling wp-cron. We'll finish with a real troubleshooting section covering the four failures this file specifically causes, and an FAQ section answering what everyone asks after their first bad edit.
What is the wp-config.php file and where does it come from?
WordPress is open source, and the copy of the files you download from the official site is the same for everyone — it doesn't know your database, its password or your domain name. So how does this generic copy become your site? The answer is wp-config.php: the one file that separates WordPress's generic code from the settings of your own installation. It is the link between the code and the data, and everything depends on the connection between it and your database.
In the copy you download, you won't find a file with this name at all. Instead you'll find a file called wp-config-sample.php — a template containing every constant with empty or dummy values. When you run the WordPress installation wizard and fill in the database details screen, WordPress takes this template, replaces the values with your details, and writes the result to a new file called wp-config.php. Control panel installers (such as Softaculous and WordPress Toolkit) do the same thing automatically behind the scenes. If writing fails because of folder permissions, WordPress displays the file's contents on screen and asks you to create it manually and paste the contents in.
When exactly is this file read?
Understanding where the file sits in the loading cycle explains why its errors are so fatal. On any request — a page, an archive, an AJAX request, even a login — execution starts at index.php, which calls wp-blog-header.php, which in turn calls wp-load.php, and the first thing wp-load.php does is look for wp-config.php and load it. In other words, this file runs before WordPress connects to the database, before the core loads, before any plugin or theme runs, and before a single character of the page is printed.
There are two practical consequences. First, any coding error in it means execution stops before WordPress has a chance to show an understandable error message — so you get a silent white screen. Second, any constant you define in it takes absolute precedence over everything after it, because it is defined first and no plugin can redefine a constant that has already been defined. That's why wp-config.php is said to "always win": what you write here overrides the settings saved in the database and whatever plugins try to impose.
Its relationship with the database
Everything you see on your site — posts, pages, comments, users, settings, even the active plugins — is stored in a MySQL/MariaDB database, not in files. The files are the engine, and the database is the content. wp-config.php is the key that opens the door between them. If this file's details are lost, or the database password changes without updating it, WordPress can't read a single character of your content, and you'll see the famous "Error establishing a database connection" message. Managing the database itself — creating it, creating a user for it and exporting a copy — is a separate topic covered in the guide to managing MySQL databases with phpMyAdmin.
Where is the file and how do you open it?
The default location is the WordPress installation root, the same folder that contains wp-admin, wp-includes and wp-content. On shared hosting this is usually public_html/wp-config.php. But watch out for two common cases: if you installed WordPress on a subdomain or in a subfolder, the path becomes something like public_html/blog/wp-config.php; and if you manage several domains on the same account, each domain has its own folder and its own configuration file. The simple rule: the file is always next to the wp-admin folder, so find the folder and you'll find the file.
There is a second acceptable location that many people don't know about: one folder above the installation root. WordPress is programmed so that if it doesn't find wp-config.php in the root, it automatically looks for it in the parent folder — provided that parent folder doesn't contain another WordPress installation. This means you can move the file one level up (to /home/user/, for example, instead of /home/user/public_html/) and the site keeps working, while the file leaves the folder the server serves to the web.
Ways to access the file
| Method | When it suits you | Important note |
|---|---|---|
| File manager in the control panel | Quick edits from the browser with no software | Use the Edit or Code Editor button, not the HTML Editor button |
| FTP / SFTP (such as FileZilla) | Frequent edits and large files | Download a copy, edit it locally, then upload it |
| SSH (command line) | VPS servers and anyone comfortable with nano or vim | The fastest way to take a backup with a single command |
| The file editor inside the WordPress dashboard | Not suitable at all | The WordPress dashboard doesn't show wp-config.php at all |
The easiest route for a beginner is the file manager in the control panel; if you're not used to its sections, the cPanel guide for beginners shows you where to find the file manager and how to navigate it. If you prefer working from your own computer, the guide to uploading files with FTP and FileZilla covers connecting, downloading and uploading step by step. Either way, the file doesn't appear inside the WordPress dashboard itself: the theme and plugin file editor in the dashboard reaches only the files in wp-content and never sees root files — and that's intentional.
Anatomy of the file from top to bottom
Open the file and you'll find it shorter than you imagined: a few dozen lines, most of them comments. But their order isn't random, and understanding that order is half the battle.
The file starts with the PHP opening tag, then a comment block explaining what's inside, and then the layers come in order: database details, the table prefix, the security keys, then the free space for constants, then the dividing line, then two final lines you don't touch: the definition of the ABSPATH constant, which sets the absolute path to the WordPress folder, and the call to wp-settings.php, which starts the whole system. These two lines are what actually "boot" WordPress, and any constant you write after them arrives far too late — after the core has already read the settings and made its decisions based on them — so it has no effect.
Database details: the heart of the file
This is the first block in the file and the most critical one, and it is the number one cause of the "Error establishing a database connection" message.
define( 'DB_NAME', 'user_wpdb' );
define( 'DB_USER', 'user_wpuser' );
define( 'DB_PASSWORD', 'put-your-password-here' );
define( 'DB_HOST', 'localhost' );
define( 'DB_CHARSET', 'utf8mb4' );
define( 'DB_COLLATE', '' );| Constant | What it means | Typical value on shared hosting |
|---|---|---|
DB_NAME | The name of the database WordPress reads from | username_wp such as acme_blog |
DB_USER | The MySQL user that has access to it | Starts with the hosting account's own prefix |
DB_PASSWORD | That user's password in plain text | A long random string — change it if it leaks |
DB_HOST | The database server address | Usually localhost; sometimes a specific server name or port |
DB_CHARSET | Character encoding | utf8mb4 — don't change it; it is what supports Arabic and emoji |
DB_COLLATE | Collation (comparison and sorting order) | Left empty so the database handles it |
Three practical notes. First: DB_HOST isn't always localhost. Some providers separate the database server from the web server and give you an address such as mysql.example.com, and some use a non-standard port, so the address becomes 127.0.0.1:3307. Never guess this value — copy it from your control panel or from the database creation message. Second: DB_CHARSET must stay utf8mb4, not the old utf8; the difference is that utf8mb4 supports four bytes per character, so emoji and some rare Arabic characters display correctly instead of as question marks. Third: the password is written here in plain, unencrypted text, and that is an unavoidable technical fact — WordPress needs it as is in order to connect. That is exactly why this file must never leave your server.
And watch out for a small detail that trips up many people: the password is written between single quotes, so if it contains a single quote or a backslash itself, it breaks the line and takes the site down. The cleanest fix is to change the password in your control panel to one that contains only letters and numbers, rather than trying to escape characters inside the string.
The table prefix: $table_prefix
Right after the database block comes a variable — not a constant — called $table_prefix:
$table_prefix = 'wp_';It means that the name of every table in the database starts with this prefix: wp_posts, wp_options, wp_users and so on. Its original purpose is purely technical: to let you install more than one WordPress site in a single database without their tables colliding, by giving each installation a different prefix.
Arabic-language content often claims that changing the prefix from wp_ to something random is "an important security measure." The truth is more nuanced: it thwarts some blind, automated SQL injection attacks that assume the default names, but it doesn't stop an attacker who can read the table names in the first place, and it doesn't make up for updating your plugins. More importantly, changing the prefix on a live site is a risky operation that requires renaming every table and editing values inside both wp_options and wp_usermeta; a single mistake can cost you your admin privileges. If you want a custom prefix, choose it at installation time, not afterwards.
And don't confuse two completely different prefixes. The table prefix ($table_prefix) is one thing, and the hosting account prefix is another. Control panels automatically add your account name as a prefix to database names and database users — so if you create a database called blog and your account is acme, the actual name becomes acme_blog, and you must write it in full in DB_NAME, not shortened. Forgetting this prefix is a very common cause of connection failures after moving a site from one server to another, and it has nothing whatsoever to do with $table_prefix.
Security keys (salts): eight constants you can't ignore
The third block in the file is eight constants with long random values:
define( 'AUTH_KEY', 'long random value' );
define( 'SECURE_AUTH_KEY', 'long random value' );
define( 'LOGGED_IN_KEY', 'long random value' );
define( 'NONCE_KEY', 'long random value' );
define( 'AUTH_SALT', 'long random value' );
define( 'SECURE_AUTH_SALT', 'long random value' );
define( 'LOGGED_IN_SALT', 'long random value' );
define( 'NONCE_SALT', 'long random value' );Their job isn't to encrypt passwords — passwords are stored hashed in the database. Their job is to sign and obscure the cookies and verification tokens (nonces) WordPress uses to know that you are you. The cookie that keeps you logged in is signed with these keys; without them, forging an admin session becomes much easier. That's why you must never leave the default values put your unique phrase here as they are, or copy one site's keys to another site.
| Constant | What it secures |
|---|---|
AUTH_KEY and AUTH_SALT | The authentication cookie over an unencrypted connection |
SECURE_AUTH_KEY and SECURE_AUTH_SALT | The authentication cookie over a secure HTTPS connection |
LOGGED_IN_KEY and LOGGED_IN_SALT | The cookie that proves you're logged in (for the admin bar, for example) |
NONCE_KEY and NONCE_SALT | Verification tokens that protect forms and links from request forgery |
These values are generated by the official WordPress secret key service, a page that produces eight lines ready to copy every time you refresh it. The method: open the service, copy all eight lines, then delete the eight old lines from your file and paste the new ones in their place. Don't keep two copies of the same constant — a duplicate definition produces a PHP warning that may appear on screen.
Development and debugging constants
This block isn't in the file by default (except WP_DEBUG set to false); you add it yourself when you need it.
define( 'WP_DEBUG', true );
define( 'WP_DEBUG_LOG', true );
define( 'WP_DEBUG_DISPLAY', false );
@ini_set( 'display_errors', 0 );This four-part combination is the only safe setup on a live site: turn on debugging, write it to a log, and don't display it on screen. The result is a text file at wp-content/debug.log that records every error, warning and deprecation notice with its time, which you can open and read at your leisure instead of chasing symptoms. WP_DEBUG_DISPLAY set to true, on the other hand, prints errors straight in front of visitors — and they reveal file paths on the server, function names and sometimes parts of queries, which makes them an information leak that helps attackers.
| Constant | Value | What it does |
|---|---|---|
WP_DEBUG | true / false | The master switch: turns on debug mode as a whole |
WP_DEBUG_LOG | true or a file path | Writes errors to wp-content/debug.log or to a path you specify |
WP_DEBUG_DISPLAY | false on a live site | Prevents errors from being printed inside the page |
SCRIPT_DEBUG | true | Loads the uncompressed JS/CSS versions to make tracing easier |
SAVEQUERIES | true | Saves every query on the page for analyzing slowness — heavy, for debugging only |
WP_ENVIRONMENT_TYPE | production / staging / development / local | Declares the environment type so plugins can behave accordingly |
WP_DEVELOPMENT_MODE | theme / plugin / core / all | Disables some internal caching layers during development |
To control where the log goes, write a path instead of true — this is the better option for security:
define( 'WP_DEBUG_LOG', '/home/user/logs/wp-errors.log' );The golden rule here: test on a copy, not the original. Turning on debugging, testing constants and disabling plugins all naturally belong in a staging environment, where you can break whatever you like without a single visitor seeing anything.
Practical security constants
This is where the file adds the most value to your site, with no more than three lines:
define( 'DISALLOW_FILE_EDIT', true );
define( 'FORCE_SSL_ADMIN', true );
define( 'DISALLOW_FILE_MODS', true );| Constant | What exactly it prevents | When to use it |
|---|---|---|
DISALLOW_FILE_EDIT | Hides the theme and plugin editor inside the dashboard | On every site, always |
FORCE_SSL_ADMIN | Forces HTTPS for the dashboard and the login page | After installing a valid SSL certificate |
DISALLOW_FILE_MODS | Prevents installing, updating and deleting plugins and themes from the dashboard | Production sites managed with Git or a controlled deployment |
DISALLOW_UNFILTERED_HTML | Prevents even administrators from inserting raw HTML | Sites with multiple editors |
WP_AUTO_UPDATE_CORE | Sets the core automatic update behavior (true / 'minor' / false) | Set it to 'minor' at a minimum |
The first constant has the highest return for the effort on the entire list. The file editor built into the WordPress dashboard lets anyone with admin privileges write PHP code that runs on the server immediately. This means that compromising a single admin account — with a leaked password, for example — turns directly into code execution on your server. Disabling the editor cuts off this path entirely, and it costs you nothing, because real theme editing belongs in an external editor or FTP anyway.
FORCE_SSL_ADMIN, for its part, ensures that the username and password don't cross the network in readable text. Its prerequisite is that the certificate is installed and actually working — otherwise you'll fall into an endless redirect loop. Install the certificate first following the guide to installing SSL and enabling HTTPS, confirm that the site opens on https:// without a warning, then add the constant. And if your site is behind a reverse proxy or a CDN that terminates the encrypted connection, WordPress may need an extra line telling it so:
if ( isset( $_SERVER['HTTP_X_FORWARDED_PROTO'] ) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https' ) {
$_SERVER['HTTPS'] = 'on';
}Performance and content constants
This block addresses two common problems: running out of memory and a bloated database.
define( 'WP_MEMORY_LIMIT', '256M' );
define( 'WP_MAX_MEMORY_LIMIT', '512M' );
define( 'WP_POST_REVISIONS', 5 );
define( 'AUTOSAVE_INTERVAL', 300 );
define( 'EMPTY_TRASH_DAYS', 7 );
define( 'WP_CACHE', true );| Constant | Default value | Practical effect |
|---|---|---|
WP_MEMORY_LIMIT | 40M for a single site | Raises the memory ceiling for site pages — a common fix for the memory exhausted error |
WP_MAX_MEMORY_LIMIT | 256M | A higher ceiling used by the dashboard and heavy tasks such as image uploads |
WP_POST_REVISIONS | Unlimited | Limits the number of revisions saved per post (false disables them entirely) |
AUTOSAVE_INTERVAL | 60 seconds | Spaces out autosaves, which reduces the load on the editor |
EMPTY_TRASH_DAYS | 30 days | Shortens how long deleted items stay in the trash before being permanently deleted |
WP_CACHE | Not defined | Enables the advanced caching layer; caching plugins usually add it themselves |
WP_MEMORY_LIMIT is the most misunderstood constant on the list. It doesn't increase your server's memory; it asks PHP to raise the allowed ceiling — and if your hosting provider has set a lower limit at the server level, your request is simply ignored. In other words, writing 1024M here on a limited shared plan will do nothing except give you a false sense of security. The practical value in most cases is between 256M and 512M; if the error keeps coming back, the problem is either a plugin that devours memory or your plan has genuinely reached its resource ceiling and it's time to upgrade.
WP_POST_REVISIONS, meanwhile, has a large, cumulative effect on the database. By default, WordPress saves every version of every edit forever; a post you've edited twenty times leaves twenty extra rows in the posts table, along with rows in other tables. On a blog with hundreds of posts, that means thousands of dead rows that slow down every query. Limiting the number to five revisions keeps a reasonable safety net without the bloat — and it's a basic step in optimizing your WordPress database.
As for WP_CACHE, don't add it manually if you use a caching plugin. Caching plugins add this constant themselves when activated and remove it when deactivated, along with an advanced-cache.php file inside wp-content; defining it manually without that file can produce a warning or strange behavior. Leave the job to the caching plugin you choose, and only add the line if your provider explicitly asks you to.
Site URLs: WP_HOME and WP_SITEURL
These two constants deserve a section of their own, because they rescue sites and break sites in equal measure:
define( 'WP_HOME', 'https://example.com' );
define( 'WP_SITEURL', 'https://example.com' );WP_SITEURL is the address of the WordPress files, and WP_HOME is the address visitors type to reach your home page. In a standard installation they are identical. When you define them here, two things happen: first, they override the values saved in the database and become the source of truth; and second, the two fields on the General Settings page of the WordPress dashboard appear disabled — because editing them there no longer means anything.
When do they help? In one well-known case: someone enters a wrong address in the settings, and the site becomes completely unreachable — the dashboard along with it — so you're locked out of your own site. Defining the two constants in wp-config.php is then the lifeline that brings the site back immediately without touching the database. They also help while moving a site from one server to another, to pin the address temporarily until the migration is complete.
The real danger here is forgetting about them. As long as the two constants are defined, changing your site address from the dashboard will do nothing at all, and you'll spend an hour puzzled about why nothing changes no matter how many times you save. So the rule is: if you define them to fix a temporary problem, delete them once the problem is over; and if you keep them permanently, make updating them a fixed item in your domain-change procedure.
Disabling the internal wp-cron
WordPress runs its scheduled tasks — publishing scheduled posts, backups, update checks — through an internal mechanism called wp-cron. The problem is that this mechanism depends on visits: it only runs when someone opens a page on your site. The result is two opposite flaws: on a site with no visitors, tasks are delayed or don't run at all, while a site with heavy traffic calls wp-cron.php thousands of times an hour and wastes its resources needlessly.
The usual fix is a single line:
define( 'DISABLE_WP_CRON', true );The command you'll put in the cron job looks like this:
wget -q -O - "https://example.com/wp-cron.php?doing_wp_cron" >/dev/null 2>&1How do you edit the file safely?
These steps aren't decoration — each one has prevented a real failure for someone before:
- Make a copy of the file first. Copy it as
wp-config-backup-2026-07-30.phpand keep it outside the web-served folder, or download it to your computer. A full backup of the site is even better, following the WordPress backup guide. - Use a plain text editor. The code editor in your control panel, or Notepad++ or VS Code on your computer. Don't use Word or any rich-text editor: these programs add hidden formatting and turn straight quotes into curly ones, which breaks the code.
- Write above the dividing line. Every new
definegoes before the line/* That's all, stop editing! ... */. - Change one thing at a time. Add a constant, save, refresh the site, confirm it works, then move on to the next. If you add five constants at once and the site goes down, you won't know which one caused it.
- Save with UTF-8 encoding without a BOM. The BOM is a set of invisible bytes at the start of the file that causes the headers error — and most editors let you choose "UTF-8 without BOM" when saving.
- Don't leave a blank line at the top or bottom. The file starts with the PHP opening tag on the very first line, and it's best if it has no closing tag at the end at all.
✅ Put it in wp-config.php | ❌ Don't put it there |
|---|---|
define constants for configuring WordPress | WordPress functions such as add_filter or add_action |
| Database connection details | Code that prints any text output |
| Security keys (salts) | Theme code or anything that belongs in functions.php |
| Runtime environment and debugging settings | API keys for external services without a need |
| Reverse proxy configuration lines if needed | A PHP closing tag at the end of the file |
How do you protect wp-config.php?
The file contains your database password, so protecting it is a priority, not a luxury:
| Measure | How | Effect |
|---|---|---|
| Set the file permissions | 600 or 640 | Prevents other users on the server from reading it |
| Block web access | A Files block in .htaccess | The server responds with a 403 error to any direct access attempt |
| Move it one level up | To the parent folder of the installation root | An optional extra layer, not a substitute for the above |
| Exclude it from Git | A line in .gitignore | Prevents the password from leaking in a public repository |
| Never share it | A behavioral rule | Not in a support ticket, not in a chat group |
The protection rule in the .htaccess file — on Apache and LiteSpeed servers — looks like this:
<Files wp-config.php>
Require all denied
</Files>The details of this file, its rules and its possible errors are explained in the .htaccess file guide. Note that Nginx servers don't read this file at all and need an equivalent rule in the server configuration, set by your provider.
The most important thing remains: always assume this file might be read someday. So if you suspect it has leaked — you sent it to a freelance developer, left it in a public repository, or malware was discovered on your site — the first step is to change the database password in your control panel and then update DB_PASSWORD in the file, and the second step is to regenerate all eight security keys. The first cuts off anyone holding your old credentials, and the second cuts off every existing session.
Troubleshooting after editing the file
| Symptom | Most likely cause | Direct fix |
|---|---|---|
| A completely blank white screen | A missing semicolon, an unclosed parenthesis or a curly quote | Restore the file from the backup, then add one change |
| "Error establishing a database connection" | A mistake in DB_NAME, DB_USER, DB_PASSWORD or DB_HOST | Match the four values character by character against the control panel |
headers already sent with a line number | A space or blank line before the PHP opening tag or after its closing tag, or a BOM | Delete everything before the first tag and save without a BOM |
| All users suddenly logged out | The security keys (salts) changed | Log in again — this is normal, expected behavior |
| An endless redirect loop | FORCE_SSL_ADMIN without a valid certificate, or WP_HOME with a wrong address | Comment out the line by putting // in front of it and refresh the page |
| A constant you added "doesn't work" | It was written below the That's all, stop editing! line | Move it above the dividing line |
| Sections missing from the dashboard | DISALLOW_FILE_MODS is enabled | Remove it if you need to install and update from the dashboard |
A white screen right after saving
This is the most common failure, and in 90% of cases it's caused by a simple syntax error: a missing semicolon at the end of a define line, an unclosed parenthesis, or a curly quote copied by a rich-text editor instead of a straight one. Because the file runs before everything else, WordPress gets no chance to display any message. The fastest and most reliable fix: put the backup back in place of the file. Then add your change again one line at a time, checking after each. And if you didn't take a backup — a lesson you'll only need to learn once — review the last line you added character by character. The white screen and its other causes (a plugin, the theme, memory) are covered in the guide to fixing common WordPress errors.
"Error establishing a database connection"
This message means the file ran successfully, but its credentials didn't get through to the database. The logical order of checks: first make sure DB_NAME is written with the full prefix (acme_blog, not blog), then that DB_USER is the correct user and that it's actually assigned to that database with full privileges — a step everyone forgets after creating a new user. Next, try temporarily changing the password in your control panel to a simple one and updating it in the file; if the site works, the problem was the password or a special character in it. Finally, DB_HOST: if you're sure about the first three, try 127.0.0.1 instead of localhost, or check with your provider. You can run all of these checks safely from phpMyAdmin without touching your data.
headers already sent
This message tells you plainly that something was printed before PHP sent the response headers, and it usually names the file and the line number where the output started. When the file named is wp-config.php, the cause is always one of three things: a space or blank line before the PHP opening tag at the start of the file, a blank line after the closing tag at the end, or a hidden BOM added by the editor. The fix: open the file, make sure the very first character on the first line is the start of the PHP opening tag with nothing before it, remove the closing tag from the end entirely (the closing tag is optional in a pure PHP file, and omitting it is the recommended practice), then save with UTF-8 encoding without a BOM.
All users suddenly logged out
If you — along with every user on the site — suddenly find yourself logged out of the dashboard without warning, the most likely cause is that the security keys changed: either you changed them yourself, a security plugin regenerated them as a preventive measure, or you restored an older backup with different keys. This isn't a malfunction; log in again and everything will work. But if the logouts keep happening every few hours for no reason, look for a plugin that rewrites the file, or for mismatched keys between two servers behind a load balancer. And if you didn't change anything at all and this happened suddenly, treat it as a warning sign and immediately start by checking for malware with the guide to detecting and removing malware before anything else.
A quick checklist before you close the file
Before you save and close, run through these six points: Did you take a backup? Are all your new constants above the dividing line? Do the four database values exactly match what's in your control panel? Are all eight security keys present, and not the default values? Is WP_DEBUG_DISPLAY set to false if debugging is enabled? Are the file permissions 600 or 640? If you answered yes to all six, you're in better shape than the vast majority of Arabic WordPress sites.
And remember that this file is just one layer in a wider system: the constants we've covered close specific doors, but they don't make up for a strong password, two-factor authentication, regularly updating plugins and themes, or backups that are actually tested rather than taken and forgotten. Make wp-config.php a solid foundation to build on, not a ceiling to settle for.
Frequently asked questions
Where exactly do I find the wp-config.php file?
In the root of your WordPress installation, the same folder that contains wp-admin, wp-includes and wp-content — usually public_html on shared hosting. If you installed WordPress in a subfolder, the path becomes something like public_html/blog/wp-config.php. It may also sit one folder above the root, because WordPress looks there automatically if it doesn't find it in its usual place. You reach it through the file manager in your control panel or over FTP; you won't find it inside the WordPress dashboard, because its editor never shows root files at all.
What if I delete the file by mistake?
Your site stops immediately and shows the WordPress installation screen again, because the system thinks it isn't installed. But your content is completely safe in the database and hasn't been touched. The fix: restore the file from your backup if you have one. If you don't, copy wp-config-sample.php to wp-config.php, fill in the four database details, add new security keys generated by the official service, and set $table_prefix to the correct prefix you see in your table names in phpMyAdmin.
Does changing the security keys delete my data?
Not at all. The keys are only used to sign cookies and verification tokens; they have nothing to do with posts, pages, images or user accounts. The only effect is that all open sessions end immediately, so everyone — you included — is asked to log in again with the same usual passwords. That's why changing the keys is recommended as soon as you suspect a hack, or after an employee with an admin account leaves: it is the fastest way to cut off every existing session in a single second.
Why doesn't the constant I added work?
Check three things in order. First, and most common: the line is written below /* That's all, stop editing! */ instead of above it — anything after that line is not read as configuration. Second: a mistake in the constant's name or syntax. Names are case-sensitive and written entirely in uppercase; the boolean values true and false are written without quotes, while string values such as '256M' take them. Third: the constant is defined twice in the file — the first definition always wins and the second is ignored with a warning.
Should I really move the file outside public_html?
You can: WordPress automatically looks in the parent folder if it doesn't find the file in the root, so moving it one level up keeps the site working. But its security benefit is debatable. It protects against one rare case — PHP execution stopping so the file is served as text — and it doesn't protect against a plugin vulnerability that reads files or against weak server isolation. If you do it, don't count it as a security achievement; focus your effort on 600 permissions, blocking web access and regular updates.
What is the difference between WP_DEBUG, WP_DEBUG_LOG and WP_DEBUG_DISPLAY?
WP_DEBUG is the master switch that turns on debug mode as a whole; without it, the other two constants do nothing. WP_DEBUG_LOG determines where errors are written: with true they go to wp-content/debug.log, and you can give it a custom path outside the web-served folder, which is the safer option. WP_DEBUG_DISPLAY determines whether errors are printed on screen in front of visitors. On a live site: the first is true, the second true or a path, and the third always false — because displaying errors reveals your server's paths to attackers.
Is DISABLE_WP_CRON enough to improve my site's performance?
No — on its own it can actually break your site. The constant stops the internal mechanism that runs scheduled tasks on every visit, but it doesn't replace it with anything. Without a second step, the following stop silently: scheduled posts, automatic backups, subscription emails and update checks — with no warning message at all. The second step is mandatory: create a real cron job on the server that calls wp-cron.php every five or ten minutes, from your control panel or over SSH.
Can I put regular PHP code in wp-config.php?
Technically yes, but in practice don't, except in rare cases of necessity. The file is loaded before the WordPress core, so functions such as add_filter and add_action won't work because the system hasn't loaded yet. And any code that prints output will immediately cause a headers already sent error. The acceptable exceptions are limited: reverse proxy configuration lines and defining environment variables. Functional changes belong in the functions.php file of a child theme, or in a small plugin of your own — both are easier to disable when something breaks.
Sources
- WordPress Developer Resources — the wp-config.php file
- WordPress documentation — Editing wp-config.php
- WordPress — Hardening your installation
Frequently asked questions
Where exactly do I find the wp-config.php file?
In the root of your WordPress installation, the same folder that contains wp-admin, wp-includes and wp-content — usually public_html on shared hosting. If you installed WordPress in a subfolder, the path becomes something like public_html/blog/wp-config.php. It may also sit one folder above the root, because WordPress looks there automatically if it doesn't find it in its usual place. You reach it through the file manager in your control panel or over FTP; you won't find it inside the WordPress dashboard, because its editor never shows root files at all.
What if I delete the file by mistake?
Your site stops immediately and shows the WordPress installation screen again, because the system thinks it isn't installed. But your content is completely safe in the database and hasn't been touched. The fix: restore the file from your backup if you have one. If you don't, copy wp-config-sample.php to wp-config.php, fill in the four database details, add new security keys generated by the official service, and set $table_prefix to the correct prefix you see in your table names in phpMyAdmin.
Does changing the security keys delete my data?
Not at all. The keys are only used to sign cookies and verification tokens; they have nothing to do with posts, pages, images or user accounts. The only effect is that all open sessions end immediately, so everyone — you included — is asked to log in again with the same usual passwords. That's why changing the keys is recommended as soon as you suspect a hack, or after an employee with an admin account leaves: it is the fastest way to cut off every existing session in a single second.
Why doesn't the constant I added work?
Check three things in order. First, and most common: the line is written below / That's all, stop editing! / instead of above it — anything after that line is not read as configuration. Second: a mistake in the constant's name or syntax. Names are case-sensitive and written entirely in uppercase; the boolean values true and false are written without quotes, while string values such as '256M' take them. Third: the constant is defined twice in the file — the first definition always wins and the second is ignored with a warning.
Should I really move the file outside public_html?
You can: WordPress automatically looks in the parent folder if it doesn't find the file in the root, so moving it one level up keeps the site working. But its security benefit is debatable. It protects against one rare case — PHP execution stopping so the file is served as text — and it doesn't protect against a plugin vulnerability that reads files or against weak server isolation. If you do it, don't count it as a security achievement; focus your effort on 600 permissions, blocking web access and regular updates.
What is the difference between WP_DEBUG, WP_DEBUG_LOG and WP_DEBUG_DISPLAY?
WP_DEBUG is the master switch that turns on debug mode as a whole; without it, the other two constants do nothing. WP_DEBUG_LOG determines where errors are written: with true they go to wp-content/debug.log, and you can give it a custom path outside the web-served folder, which is the safer option. WP_DEBUG_DISPLAY determines whether errors are printed on screen in front of visitors. On a live site: the first is true, the second true or a path, and the third always false — because displaying errors reveals your server's paths to attackers.
Is DISABLE_WP_CRON enough to improve my site's performance?
No — on its own it can actually break your site. The constant stops the internal mechanism that runs scheduled tasks on every visit, but it doesn't replace it with anything. Without a second step, the following stop silently: scheduled posts, automatic backups, subscription emails and update checks — with no warning message at all. The second step is mandatory: create a real cron job on the server that calls wp-cron.php every five or ten minutes, from your control panel or over SSH.
Can I put regular PHP code in wp-config.php?
Technically yes, but in practice don't, except in rare cases of necessity. The file is loaded before the WordPress core, so functions such as add_filter and add_action won't work because the system hasn't loaded yet. And any code that prints output will immediately cause a headers already sent error. The acceptable exceptions are limited: reverse proxy configuration lines and defining environment variables. Functional changes belong in the functions.php file of a child theme, or in a small plugin of your own — both are easier to disable when something breaks.