Home / WordPress Guides / WordPress Basics / How to Edit wp-config.php Safely in WordPress

How to Edit wp-config.php Safely in WordPress

TABLE OF CONTENTS

Free WordPress Site Review

Is your WordPress setup ready for what 2026 demands?

TL;DR

To edit wp-config.php, access your WordPress files through your hosting File Manager or SFTP, locate the configuration file, and save an unchanged backup before making changes. Use a plain-text code editor, modify only the setting you need, then save the file and check that your website still works.

Important: wp-config.php contains sensitive database credentials and authentication keys. Keep backup copies private and make sure you can restore the original file if WordPress stops loading.

Most WordPress settings can be changed from the dashboard. Database connection details, debugging options, and certain other settings are different: they’re controlled through wp-config.php, a PHP configuration file that WordPress reads when loading the site.
Editing it may be necessary when troubleshooting a database connection problem, enabling diagnostic logging, or following instructions from your hosting provider. A missing quote or incorrect value, however, can prevent WordPress from loading.
The safest approach is to understand the setting you’re changing, preserve the original file, and have a way to restore it without relying on the WordPress dashboard.

What Is wp-config.php in WordPress?

wp-config.php is a PHP configuration file that provides WordPress with essential configuration settings, including the information needed to connect to its database.

It’s normally located in the WordPress installation directory, alongside wp-admin, wp-content, and wp-includes. In supported configurations, it can also be stored one directory above the installation.
The file typically contains:
  • Database settings: DB_NAME, DB_USER, DB_PASSWORD, and DB_HOST.
  • Authentication keys and salts: Values used as part of WordPress authentication and cookie security.
  • Database table prefix: The $table_prefix variable identifying the installation’s database tables.
  • Debugging settings: Constants such as WP_DEBUG.
  • Additional configuration: Optional settings that affect WordPress behavior.
The exact contents can vary depending on the hosting environment.
Because the file contains sensitive information, never publish its contents or share unredacted screenshots.
wp-config.php doesn’t contain your posts, pages, or database itself. It contains settings WordPress uses to connect to and work with those resources.

Before Editing wp-config.php

A mistake in wp-config.php can prevent WordPress from loading. Before changing anything, prepare a way to restore the original configuration.

1. Confirm file access. Make sure you can access your WordPress files through File Manager, SFTP, or SSH. Some managed hosting providers handle configuration differently.

2. Save an unchanged backup. Download wp-config.php and store it securely outside your website’s public directory. Don’t expose database credentials or authentication keys.

Download wp-config.php file

3. Check your recovery options. Confirm that you can restore the original file even if the WordPress dashboard becomes unavailable. A configuration backup isn’t a substitute for a complete website and database backup. For ongoing protection, consider automated WordPress backups that cover both files and database content.

4. Use staging when possible. Test changes away from the live website, especially when troubleshooting server-related issues. If you don’t have a staging environment, follow our WordPress staging setup guide before modifying your production site.

Before continuing, know exactly which setting needs to change and how you’ll reverse it if necessary.

How to Find wp-config.php in WordPress

Look for wp-config.php in the directory containing the wp-admin, wp-content, and wp-includes folders.
If it isn’t there, check one directory above the WordPress installation. The exact location depends on your hosting setup.

Method 1: Find wp-config.php Using cPanel File Manager

1. Log in to your hosting account and open cPanel → File Manager.

File Manager - cpanel

2. Navigate to the website’s document root. This is often public_html, but other domains may use different directories.

3. Find the wp-admin, wp-content, and wp-includes folders.

4. Look for wp-config.php alongside them.

wp-config file

5. If it isn’t present, check the parent directory.

Make sure you’re browsing the correct website if your hosting account contains multiple installations.

Method 2: Find wp-config.php Using SFTP

An SFTP client such as FileZilla allows you to browse server files through an encrypted connection.

1. Open your SFTP client and select the SFTP protocol.

2. Connect using the hostname, username, authentication details, and port provided by your host. SFTP commonly uses port 22, but your provider may configure another port.

3. Navigate to the WordPress installation directory.

4. Find wp-config.php alongside the main WordPress folders, or check the parent directory.

FTP Client navigating to edit wp-config.php file
Confirm you’re viewing the remote server’s files, not a local folder on your computer.
Use SFTP rather than unencrypted FTP when transferring configuration files.

Method 3: Find wp-config.php Using SSH

If your hosting provider supports SSH, connect to the server and navigate to your WordPress directory.
For a typical installation under public_html, you might use:
cd ~/public_html
List the directory contents:
ls -la
If wp-config.php isn’t visible, inspect the parent directory:
ls -la ..
These commands only navigate and list files; they don’t change the configuration.

If you still can’t locate the file, verify the installation path with your hosting provider rather than creating a replacement.

How to Edit wp-config.php Safely

Once you’ve located the file and saved an unchanged backup, make only the configuration change needed for your task.

1. Open the file. Use your hosting File Manager’s Edit option, or download a working copy through SFTP and open it in a plain-text code editor. Avoid word processors.

2. Find the existing setting. Search for the constant or variable you need. If it’s already defined, change that definition rather than creating a duplicate.

3. Edit carefully. Preserve PHP syntax, including quotation marks, parentheses, and semicolons. Don’t alter unrelated settings. When adding a new WordPress constant, follow its documented placement requirements, generally before WordPress loads wp-settings.php.

4. Save and apply the change. Keep the filename `wp-config.php` and save it as plain-text UTF-8 without BOM. If you edited the file directly in cPanel’s editor, save it there. If you edited a downloaded copy, upload it to the correct directory using cPanel File Manager or SFTP, replacing the intended file only after verifying its location.

Uploading wp-config.php file via cPanel

Uploading a modified file through SFTP

Uploading wp-config.php file via FTP Client

5. Check the result. Test the homepage, an internal page, the dashboard, and the setting you changed. If WordPress stops working, restore your original file through File Manager or SFTP.

A successful upload doesn’t necessarily mean the configuration is correct. Change and verify one setting at a time.

Common wp-config.php Changes

Most WordPress users won’t need to edit this file regularly. These are three settings you may encounter when resolving a specific issue.

Enable WordPress Debug Logging

WordPress debugging can help identify plugin, theme, or PHP errors that aren’t immediately visible.

For temporary troubleshooting, preferably on staging, the following settings enable debugging, write messages to wp-content/debug.log by default, and disable their on-screen display:
define( 'WP_DEBUG', true ); define( 'WP_DEBUG_LOG', true ); define( 'WP_DEBUG_DISPLAY', false );
Check whether these constants already exist before adding them.
Debug logs may contain sensitive information. Keep them protected, and disable temporary debugging and logging when the investigation is complete.

Update Database Connection Settings

WordPress uses the following constants to connect to its database:
define( 'DB_NAME', 'database_name' ); define( 'DB_USER', 'database_user' ); define( 'DB_PASSWORD', 'database_password' ); define( 'DB_HOST', 'localhost' );
These values are placeholders. Your actual database host may differ from localhost.
Only update these settings when you have the correct database credentials.

Changing DB_PASSWORD in the file doesn’t change the database user’s actual password. Both values must match, or WordPress may display an Error establishing a database connection message.

If the database issue also prevents you from accessing WordPress, our WordPress login troubleshooting guide covers additional checks for database connection and admin access problems.

Adjust the WordPress Memory Limit

WordPress supports the WP_MEMORY_LIMIT constant, which can request a higher PHP memory limit for WordPress operations.
For instance:
define( 'WP_MEMORY_LIMIT', '256M' );
This is an example, not a recommended value for every website.
The effective limit depends on PHP and hosting restrictions. Increasing WP_MEMORY_LIMIT may not solve a memory error if the server enforces a lower limit or a plugin is consuming excessive resources.
Check the underlying error before changing the value.

How to Restore wp-config.php if Something Goes Wrong

If WordPress stops working immediately after editing wp-config.php, restoring the previous version is usually the fastest way to reverse the configuration change.

1. Access your website files through your hosting File Manager or SFTP. You don’t need the WordPress dashboard for this.

2. Locate the modified wp-config.php in its original directory.

3. Restore your unchanged backup, making sure the filename is exactly wp-config.php and that you’re replacing the file in the correct WordPress installation.

4. Test the website again, including the homepage and WordPress dashboard.

If the site works after restoring the backup, review your attempted changes before trying again.

Important: Restoring the original file only reverses changes made to that file. If you also changed database credentials, server settings, or other files, additional recovery steps may be necessary.

If restoring the original configuration doesn’t bring your website back online, a one-time WordPress fix may be appropriate for diagnosing and resolving the underlying technical issue.

Troubleshooting and Security Best Practices

If restoring wp-config.php doesn’t resolve the problem, the error message can help narrow down the cause.
Problem What to check
Error establishing a database connection Verify DB_NAME, DB_USER, DB_PASSWORD, and DB_HOST. If they haven’t changed, check whether the database server is available.
PHP syntax error or HTTP 500 Review the edited lines for missing semicolons, incorrect quotation marks, or other syntax errors. Check the server’s PHP error log if available.
Changes cannot be saved Confirm file ownership and permissions with your hosting provider. Don’t make the file publicly writable to bypass an access problem.
Unexpected behavior after editing Compare the modified file with your backup and check whether the change was applied to the correct WordPress installation.

Keep the Configuration File Protected

wp-config.php contains sensitive information, so its security matters beyond the editing process.
  • Use secure access: Prefer SFTP or SSH over unencrypted FTP.
  • Restrict file permissions: Use the most restrictive permissions compatible with your hosting environment. WordPress documents 400 or 440 as options in suitable configurations, but there’s no single value that works for every server.
  • Protect backup copies: Store them outside publicly accessible website directories.
  • Remove unnecessary debug logs: Logs may contain sensitive information. Protect their access and disable temporary debugging when troubleshooting is complete.
If the problem persists, contact your hosting provider or a WordPress specialist before changing unrelated configuration settings.

Conclusion

Editing wp-config.php should be a controlled change, not trial and error. Keep an unchanged backup, modify only the setting you understand, and verify the result before making further adjustments.

If WordPress stops loading, restore the original configuration first and investigate the cause rather than changing several settings at once. Knowing when to stop and check the underlying problem is just as important as knowing how to edit the file.

If your website requires regular backups, update testing, and technical support, explore our WordPress maintenance services.

Ognjen Velickovic

WordPress Developer & Product Manager at Kiwistic. I build and maintain WordPress sites for small businesses and troubleshoot everything from login lockouts to security issues. These guides come from real experience, so you don't have to figure it out alone.

You May Also Like…