This website uses cookies

Our website, platform and/or any sub domains use cookies to understand how you use our services, and to improve both your experience and our marketing relevance.

📣 Try the fastest hosting platform with pay-as-you-go pricing & 24/7 expert support! MIGRATE NOW →

A Comprehensive Guide to Setting Up the wp-config.php File for WordPress

Updated on November 16, 2023

12 Min Read
main

The wp-config.php file is the backbone of your website’s configuration. If anything happens to this file, your site can go down or be corrupted.

Therefore, you must be careful while making any changes to it,t as it can expose you to several risks, including security threats or causing your site to break.

But to help you correctly configure your WordPress site, this blog will step down all the right methods to edit the wp-config.php file. So, let’s dive in.

What is the wp-config File?

The wp-config file is among your site’s most crucial files. It has all the configuration details that a site requires to function properly. It also stores database information such as the database name, username, password, and host. You’ll find this file in your WordPress installation’s root directory.

What Is the Purpose of wp-config File?

The wp-config file in WordPress is a crucial configuration file that sets the base settings for your website to function properly. It’s where you provide the details of your website’s database connection—that is, where your site’s content and settings are stored.

This file also houses unique security keys that add an extra layer of protection to your site, keeping it safe from hacking attempts. Additionally, it contains settings that enable you to turn on debugging, helping you to troubleshoot and solve any issues your site encounters.

Furthermore, the wp-config file allows for fine-tuning of your site’s performance and behavior, giving you control over technical aspects to optimize how your site runs. It’s also the go-to place for customizing file management within your WordPress installation.

In the event of a problem, the wp-config file can trigger an auto-recovery mode, assisting in restoring your site’s functionality with less hassle. All in all, the wp-config file is the backbone of your WordPress site’s configuration and is essential for operation, security, and customization.

Where Is the wp-config File Located?

A common question among WordPress users, especially for beginners, is “where is wp-config.php located in your system or server?

The answer is simple, you’ll find this core file in the WordPress root directory, but it depends on the server’s location.

If you’re working on a localhost with a setup like XAMPP or WAMP, go to xampphtdocs cloudways-wp. In my case, the site folder name is “cloudways-wp”.

cloudways-wp

If you are using Cloudways, you can directly access the wp-config.php file using the Cloudways SSH terminal.

Follow these steps:

  • Log in to the Cloudways Platform
  • Click Server ManagementMaster Credentials.
  • Click Launch SSH Terminal.
  • Use your Public IP, Username, and Password to access the SSH terminal.

Launch SSH Terminal.

You can access the public_html folder with the following commands:

  • LS command to list files or directories in Linux
  • CD for changing directories

access the public_html folder

In addition to using the Cloudways SSH terminal, another viable method to access the wp-config.php file is through an FTP client, such as FileZilla.

FTP client

What Does the wp-config File Looks Like?

Here is a very basic outline of what the wp-config.php file might look like:

<?php
define( 'WP_CACHE', true ); 
/**
 * The base configurations of the WordPress.
 *
 * This file has the following configurations: MySQL settings, Table Prefix,
 * Secret Keys, WordPress Language, and ABSPATH. You can find more information
 * by visiting {@link http://codex.wordpress.org/Editing_wp-config.php Editing
 * wp-config.php} Codex page. You can get the MySQL settings from your web host.
 *
 * This file is used by the wp-config.php creation script during the
 * installation. You don't have to use the web site, you can just copy this file
 * to "wp-config.php" and fill in the values.
 *
 * @package WordPress
 */
// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define('DB_NAME', 'hvtqebrzzh');
/** MySQL database username */
define('DB_USER', 'hvtqebrzzh');
/** MySQL database password */
define('DB_PASSWORD', 'wzM8Su5MF6');
/** MySQL hostname */
define('DB_HOST', 'localhost');
/** Database Charset to use in creating database tables. */
define('DB_CHARSET', 'utf8');
/** The Database Collate type. Don't change this if in doubt. */
define('DB_COLLATE', '');
/**#@+
 * Authentication Unique Keys and Salts.
 * Change these to different unique phrases!
 * You can generate these using the {@link https://api.wordpress.org/secret-key/1.1/salt/ WordPress.org secret-key service}
 */
require('wp-salt.php');
/**
 * WordPress Database Table prefix.
 *
 * You can have multiple installations in one database if you give each a unique
 * prefix. Only numbers, letters, and underscores please!
 */
/**
 * WordPress Database Table prefix.
 *
 * You can have multiple installations in one database if you give each a unique
 * prefix. Only numbers, letters, and underscores please!
 */
$table_prefix  = 'wp_';
/**
 * WordPress Localized Language, defaults to English.
 *
 * Change this to localize WordPress. A corresponding MO file for the chosen
 * language must be installed to wp-content/languages. For example, install
 * de_DE.mo to wp-content/languages and set WPLANG to 'de_DE' to enable German
 * language support.
 */
define('FS_METHOD','direct');
define('WPLANG', '');
define('FS_CHMOD_DIR', (0775 & ~ umask()));
define('FS_CHMOD_FILE', (0664 & ~ umask()));
/**
 * For developers: WordPress debugging mode.
 *
 * Change this to true to enable the display of notices during development.
 * It is strongly recommended that plugin and theme developers use WP_DEBUG
 * in their development environments.
 */
define('WP_DEBUG', false);
define( 'WP_REDIS_CONFIG', [
   'token' => "e279430effe043b8c17d3f3c751c4c0846bc70c97f0eaaea766b4079001c",
   'host' => '127.0.0.1',
   'port' => 6379,
   'database' => "7550", 
   'timeout' => 2.5,
   'read_timeout' => 2.5,
   'split_alloptions' => true,
   'async_flush' => true,
   'client' => 'phpredis', 
   'compression' => 'zstd', 
   'serializer' => 'igbinary', 
   'prefetch' => true, 
   'debug' => false,
   'save_commands' => false,
   'prefix' => DB_NAME,  
   ] );
define( 'WP_REDIS_DISABLED', false );
/* That's all, stop editing! Happy blogging. */
/** Absolute path to the WordPress directory. */
if ( !defined('ABSPATH') )
        define('ABSPATH', dirname(__FILE__) . '/');
/** Sets up WordPress vars and included files. */
require_once(ABSPATH . 'wp-settings.php');

How to Configure & Edit the wp-config.php File

Editing the wp-config.php file is critical when managing a WordPress website, as it contains your site’s important details. Here’s how you can edit the wp-config.php file.

Step 1: Backup Your wp-config.php File

Before making any changes to your wp-config.php file, take a backup of the existing file to ensure that you can restore it if anything goes wrong. Note: We have mentioned two methods to backup wp-config.php.Step 2: Access Your WordPress Files

You need to access your WordPress to edit the wp-config.php file. This can be done via various methods such as FTP or through Cloudways SSH Terminal. Here, we’ll access our files using FTP:

  • Connect to your server using an FTP client like FileZilla.
  • You will need your FTP credentials. If you’re a Cloudways user, get yours from the master credentials section in server management.

Step 3: Locate the wp-config.php File

The wp-config.php file is generally located in your WordPress application’s root directory. In most cases, this will be the public_html folder.

Step 4: Edit the wp-config.php File

  • Download the wp-config.php file to your local system.
  • Open the file with a text editor like Notepad (Windows) or a code editor like Visual Studio Code or Sublime Text.
  • Make the required changes.

Access wp-config.php Via Cloudways SSH Terminal

Cloudways users can directly access the wp-config.php file via its SSH terminal. Follow these steps:

  • Go to Server Management Master Credentials 
  • Launch SSH Terminal
  • Use your Public IP, Username, and Password to access the SSH terminal.

Launch SSH Terminal.

Access the public_html folder with the following commands:

  • LS (list files or directories in Linux)
  • CD (to change directories)

access the public_html folder

Open the wp-config.php file using a text editor available in your server’s environment, like nano or vi.

Open the wp-config.php file

Note: vi or nano is a text editor that works in the command line interface and SSH terminal.

vi or nano

Step 5: Save and Exit the Text Editor

Once you’ve made your changes, it’s time to save and exit. If you’re using nano:

  • Press Ctrl+O to write the changes (to save them).
  • Press Enter to confirm.
  • Press Ctrl+X to exit the editor.

Step 6: Verify Your Changes

After exiting the editor, ensure your WordPress site is functioning correctly. It’s always good to double-check that your changes haven’t caused any issues.

How to Back Up Your wp-config.php File (Manually + Using Cloudways)

You can back up your wp-config.php file in two ways: Using FTP or the Cloudways Platform.

Backing Up wp-config.php File Via FTP

If you want to take a backup via FTP, download the wp-config.php file via FTP to store it locally on your system. This strategy ensures that in the event of unintended alterations, you can swiftly restore the original file by reuploading it from your system and removing the incorrect version.

Backing Up wp-config.php File Via FTP

Backing Up wp-config.php File Via Cloudways

If you’re a Cloudways user, you can back up your entire application in 1-click with the Cloudways Backup feature. The on-demand backup feature takes a backup of your application files and database.

Here, application files mean that only the public_html and private_html folders are backed up along with the database you restore your application, then the restoration process is also applicable only to these folders and a database.

  • Select the target application you want to back up.

Select the target application

Click on Backup and Restore on the left and hit Take Backup to initiate the process.

Take Backup

The backup processing time depends on the size of the application files and the database. You will be notified once the process is completed.

backup completed

Optimize Your WP-Config with Cloudways Managed Hosting

Streamline your wp-config.php edits with Cloudways’ automated backups and advanced WordPress features. Elevate your workflow and security.

15 Common wp-config.php File Tweaks

Here are the 15 most common tweaks to edit the WP-Config file;

1. How to Bypass FTP Connection Information

If you are struggling to update the WordPress core and plugins to a newer version due to a faulty FTP connection, you can bypass the FTP connection information by adding the following line of code in the wp-config.php file:

define( 'FS_METHOD', 'direct');

2. How to Enable Debugging in WordPress

To enable the debug mode in WordPress, all you have to do is add the following lines of code in wp-config.php:

define(‘WP_DEBUG’, false); // disable debugging mode by default

define(‘WP_DEBUG’, true); // enable debugging mode

3. How to Change Site and WordPress URL

If you’ve migrated your WordPress site to a new host, changed the domain name, or wish to update the URL from HTTP to HTTPS, add the following lines of code in the wp-config.php:

define('WP_SITEURL', 'http://www.example.com');

define('WP_HOME', 'http://www.example.com');

An alternative method is to use the SERVER variable that sets these values dynamically.

define('WP_HOME', 'https://' . $_SERVER['HTTP_HOST'] );

define('WP_SITEURL', 'https://' . $_SERVER['HTTP_HOST'] );

4. How to Increase (or Decrease) PHP Memory

Cloudways users can increase or decrease the PHP memory value from the application settings instantly from the Platform.

However, non-Cloudways users need to play with the coding lines. Add the following line:

define( 'WP_MEMORY_LIMIT', '64M' );

If required, you can set the maximum memory limit:

define( 'WP_MAX_MEMORY_LIMIT', '256M' );

5. How to Edit Trash Box Timing

If a user deletes posts, pages, or comments, they are sent to the Trash Box, where WordPress automatically deletes them after 30 days.

To change this duration, you can add the following line in the wp-config file to modify this value to suit your needs. In the following example, I have decreased it to 15 days:

define( 'EMPTY_TRASH_DAYS', 15 );

You can even disable the Trash feature completely by setting the value to zero.

6. How to Disable Automatic Updates

To disable automatic updates, add the following line in wp-config.php:

define( 'AUTOMATIC_UPDATER_DISABLED', true );

If you want to disable automatic updates for your WordPress core (minor and major updates) add the following lines of code in the config file:

# Disable all core updates:

define( 'WP_AUTO_UPDATE_CORE', false );

# Enable all minor and major core updates:

define( 'WP_AUTO_UPDATE_CORE', true );

7. How to Set Autosave Intervals

When creating or editing the post, WordPress automatically saves the post revisions. The default value of the autosave interval is 60 seconds which can be increased or decreased by adding the following line:

define( 'AUTOSAVE_INTERVAL', 180 );

8. How to Set Database Prefix

When installing WordPress on your localhost setup such as XAMPP, one of the options is to select the database table prefix that is stored in the wp-config.php file as:

$table_prefix = 'wp_';

I personally recommend changinge the default prefix as a security precaution.

9. How to Enable WordPress Multisite Network

The following code will help you want to enable the multisite functionality, you need to add the following code to your wp-config.php file.

define('WP_ALLOW_MULTISITE', true);

After adding this code, a new page, “Network” will be available in the Tools section of the WordPress Admin.

Read our comprehensive guide on setting up a WordPress multisite.

10. How to Enable Error Log Configuration

To enable basic error logging for your WordPress-powered site, create a file named php_error.log in the directory of your choice and make it server-writable.

Next, edit the path in the third line of the following code and place the snippet in the wp-config.php file:

@ini_set('log_errors','On');

@ini_set('display_errors','Off');

@ini_set('error_log','/home/path/domain/logs/php_error.log');

11. How to Turn on WordPress Caching

Add the following code to the wp-config.php file to turn on the WP-Cache:

define('WP_CACHE', true);

12. How to Configure Database Settings

Here’s how you can edit database connection settings from the WordPress config file and match database values (name, user, password, and host) with your hosting database values:

/ ** MySQL settings - Get this information from your web host ** //

/** The name of the database for WordPress */

define('DB_NAME', 'Your database name');

/** MySQL database username */

define('DB_USER', 'Your database username');

/** MySQL database password */

define('DB_PASSWORD', 'Your database password');

/** MySQL hostname */

define('DB_HOST', 'localhost');

Different WordPress hosting providers use different DB_Host values, and Cloudways uses ‘localhost’ (localhost is the common DB_HOST value).

You may come across the “Error Establishing a Database Connection” error. This error usually appears when you have migrated your site and your wp-config contains old or incorrect database information. Here’s a complete guide to fix the database connection error.

13. How to Redirect Non-Existent Subfolders and Subdomains

When a visitor tries to access a subdomain or subfolder that doesn’t exist on your website, you can simply redirect your site visitors to a specific page or URL.

All you need to do is paste the following line of code into the wp-config.php file:

define( 'NOBLOGREDIRECT', 'http://example.com' );

Don’t forget to replace the “http://example.com” with your website URL.

14. How to Edit Post Revision

You can disable the post revision feature completely and also set the maximum number of revisions that WordPress can store.

To disable the post revision function, just add the following line in the WordPress config file:

define( 'WP_POST_REVISIONS', false );

To limit the number of revisions, just replace the false value with any integer. For instance, the following line limits the revisions to just 12.

define( 'WP_POST_REVISIONS', 12 );

15. How to Set a Cookie Domain

WordPress allows you to set the cookie domain for your WordPress site (for unusual domain setups) by using the following coding line:

define( 'COOKIE_DOMAIN', 'www.cloudways.com' );

Why Editing a WP-Config File is Sensitive?

Editing the wp-config.php file is a sensitive task because it directly affects the functionality and security of your WordPress site. This file contains the database connection settings, which, if entered incorrectly, can disconnect your site from its content.

It also includes security keys that encrypt information, maintaining the integrity of your site. Mistakes in editing this file can lead to security breaches or even render your site inoperable.

Additionally, the wp-config.php file controls debugging and performance parameters, which are vital for the smooth running of your site but can expose sensitive information if misconfigured.

Given its importance, any changes to the wp-config.php file should be approached with caution and ideally, performed by someone with technical expertise.

Planning to tweak your wp-config file?

With secure WordPress hosting, gain exclusive SSH and SFTP access, ensuring fortified layers of security for every change you make

How Cloudways Facilitates Editing the wp-config.php File?

Editing the WP-config file is hard. Change one thing in WP-config.php; like a line of dominos, you might inadvertently affect something else. The ripple effect is real; before you know it, you’re deep in the maze, looking for an exit.

How about choosing the hosting provider that makes your safe exit much easier? Cloudways is definitely your go-to option.

Here’s how Cloudways can facilitate editing the wp-config.php file:

  • Cloudways provides an integrated file manager in its platform where you can navigate to the root directory of your WordPress installation to find and edit the wp-config.php file.
  • It provides the users with secure SSH and SFTP access, allowing them to access and edit files on your server with utmost security.

secure SSH and SFTP access

  • Cloudways offers easy backup solutions, allowing you to restore your website to a previous state in case something goes wrong. You can find the backup option under the server tab.

backup

  •  You can manage various server and application settings directly from the Cloudways platform, manually eliminating the need to edit files like wp-config.php for many common tasks.
  • Server settings can be found under server tab.

Server settings

  • Application settings can be found on the left side of the selected application.

Application settings

Summary

And that’s it. This is how you can edit the WP-Config file. Remember to follow the necessary precautions before messing up with this file. I would also recommend you choose the perfect hosting provider with built-in features that will help you edit the Wp-config file seamlessly.

Share your opinion in the comment section. COMMENT NOW

Share This Article

Liza Rajput

Liza Rajput is a Technical Content Producer at Cloudways. Being a software engineer, she loves to play with data and its processes and wishes to grow and excel in Data Science and Big Data Engineering. She has also been an avid reader and exceptional writer, with sufficient experience in technical, research-based, and creative writing.

×

Get Our Newsletter
Be the first to get the latest updates and tutorials.

Thankyou for Subscribing Us!

×

Webinar: How to Get 100% Scores on Core Web Vitals

Join Joe Williams & Aleksandar Savkovic on 29th of March, 2021.

Do you like what you read?

Get the Latest Updates

Share Your Feedback

Please insert Content

Thank you for your feedback!

Do you like what you read?

Get the Latest Updates

Share Your Feedback

Please insert Content

Thank you for your feedback!

Want to Experience the Cloudways Platform in Its Full Glory?

Take a FREE guided tour of Cloudways and see for yourself how easily you can manage your server & apps on the leading cloud-hosting platform.

Start my tour

CYBER WEEK SAVINGS

  • 0

    Days

  • 0

    Hours

  • 0

    Mints

  • 0

    Sec

GET OFFER

For 4 Months &
40 Free Migrations

For 4 Months &
40 Free Migrations

Upgrade Now