This file wp-config.phpis the main file for the WordPress installation . It’s located in the root directory and stores all the main configuration parameters. It’s used to configure the database connection, improving site performance and security. It also allows you to enable WordPress debug mode , providing useful information during development. The file isn’t immediately available but is created when WordPress is started for the first time.

Figure 1. Parameters of the wp-config.php file

If WordPress doesn’t have the necessary write privileges to create the file, the site administrator will need to rename it wp-config-sample.phpto wp-config.php, manually setting the values ​​of the constants declared in the file. These constants are defined in a specific order that shouldn’t be altered to avoid runtime errors. Let’s see which parameters are stored in the configuration file.

 

MySQL Settings

wp-config.phpstores MySQL settings, these are stored in the following constants:

 

/** Il nome del database di WordPress */
define('DB_NAME', 'wordpress');
/** Nome utente del database MySQL */
define('DB_USER', 'root');
/** Password del database MySQL */
define('DB_PASSWORD', 'root');
/** Hostname MySQL */
define('DB_HOST', 'localhost');
/** Charset del Database da utilizzare nella creazione delle tabelle. */
define('DB_CHARSET', 'utf8mb4');
/** Il tipo di Collazione del Database. Da non modificare se non si ha idea di cosa sia. */
define('DB_COLLATE', '');
 

 

The values ​​set in the example code refer to a local installation ; when you’re not working locally, the host will provide the necessary data. Obviously, to enter the database name, you’ll need to make sure you’ve created one, as WordPress won’t create it for you.

The hostname can also be detected automatically by defining the constant DB_HOSTas follows:

 

define('DB_HOST', $_ENV{DATABASE_SERVER});
 

 

In this case, of course, the file will have to be edited manually.

This constant DB_CHARSETsets the character set to use when defining database tables. Starting with WordPress version 4.2, the default character set is no longer UTF-8 but utf8mb4, a set with identical characteristics to UTF-8 but with one additional byte per character. Support for utf8mb4improves WordPress usability in languages ​​that use the Han character set (Chinese, Japanese, Korean). In general, changing the default value is neither necessary nor recommended.

The constant DB_COLLATEsets the value of the collation, that is, the order of letters, numbers, and symbols in the character set. If left blank, the collation will be assigned based on the value of DB_CHARSET. The charset utf8mb4will correspond to the collation utf8mb4_unicode_ci. Again, it is best to leave the value of the constant unchanged.

Security keys

To ensure better encryption of information stored in cookies, wp-config.phpit uses 8 authentication keys that can be freely set by the site administrator. To generate more secure keys, you can use the WordPress secret key service . The following is an example set of keys:

Figure 2. The 8 authentication keys in wp-config.php.

Authentication keys are required for the security system. Salt keys are recommended, but not required.

 

The table prefix

During installation, WordPress generates tables in which data is stored as the site is developed and updated. Each table is assigned a name with a prefix whose default value is wp_.

Figure 3. WordPress database tables with “wp_” prefix.

To avoid SQL injections, it’s best to keep the database table names unknown. Therefore, it’s always advisable to set a prefix other than the default during installation. The set value is stored in the file wp-config.phpin the variable $table_prefix:

$table_prefix = 'wp_';
 

You can also manage multiple installations with a single database by setting a different value for the variable $table_prefixin each installation. Only numbers, letters, and the underscore are allowed.

If the site is already active, you can still change the value of $table_prefix. Once the new value has been set, you will need to update the table names and some field values: in the table, wp_optionsthe value of the field option_namecorresponding to wp_user_roles(if present) will need to be updated, while in the table, wp_usermetathe values ​​of the fields meta_keycontaining the string will need to be reset wp_.

Figure 4. wp_usermeta table.

Before modifying a working site, it is a good idea to perform a preventive backup.

In the next post, we’ll go beyond the basic settings and see how to use the configuration file to get the most out of WordPress in terms of speed and security.

 
Share.
Leave A Reply

Exit mobile version