Quando si lavora con WordPress, uno dei file più importanti è senza dubbio wp-config.php.
Questo file rappresenta il cuore delle configurazioni tecniche del sito e senza di esso la piattaforma non può funzionare correttamente.
Il file si trova nella root del sito WordPress.
Se non è presente, normalmente WP deve ancora essere installato.
Durante l’installazione, WordPress genera questo file a partire da un modello chiamato wp-config-sample.php, personalizzandolo con i dati forniti dall’utente.
Quindi procedi con l’installazione di WP oppure crealo a mano partendo dal file wp-config-sample.php.
Indice
Gestisce le configurazioni di connessione al database
Il file wp-config.php contiene i dati essenziali per permettere a WordPress di collegarsi al database, come:
// ** Database settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define( 'DB_NAME', 'database_name_here' );
/** Database username */
define( 'DB_USER', 'username_here' );
/** Database password */
define( 'DB_PASSWORD', 'password_here' );
/** Database 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', '' );
I dati principali da modificare sono:
DB_NAME: il nome del databaseDB_USER: l’utente del databaseDB_PASSWORD: la password dell’utenteDB_HOST: l’host del database (es. localhost)
Senza queste informazioni, WordPress non è in grado di comunicare con il database e quindi non può funzionare.
Gestire Sicurezza e chiavi univoche
Un altro elemento importante del file è la presenza delle Security Keys e Salts, ovvero una serie di costanti che servono a proteggere le sessioni utente e i cookie di autenticazione.
Grazie a queste chiavi, le informazioni di login vengono criptate e rese più difficili da decifrare da parte di eventuali malintenzionati.
/**#@+
* 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}.
*
* You can change these at any point in time to invalidate all existing cookies.
* This will force all users to have to log in again.
*
* @since 2.6.0
*/
define( 'AUTH_KEY', 'put your unique phrase here' );
define( 'SECURE_AUTH_KEY', 'put your unique phrase here' );
define( 'LOGGED_IN_KEY', 'put your unique phrase here' );
define( 'NONCE_KEY', 'put your unique phrase here' );
define( 'AUTH_SALT', 'put your unique phrase here' );
define( 'SECURE_AUTH_SALT', 'put your unique phrase here' );
define( 'LOGGED_IN_SALT', 'put your unique phrase here' );
define( 'NONCE_SALT', 'put your unique phrase here' );
Se vuoi modificare le chiavi Salt a mano, puoi andare a questo indirizzo: https://api.wordpress.org/secret-key/1.1/salt/ per generarne di nuove automaticamente.
Copiale ed incollale nel tuo file wp-config.php.
Gestire il prefisso delle tabelle del database
È sempre consigliato modificare il prefisso delle tabelle del database di WordPress per migliorare la sicurezza, oppure nel caso utilizzassi più blog sullo stesso database.
/**
* 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!
*
* At the installation time, database tables are created with the specified prefix.
* Changing this value after WordPress is installed will make your site think
* it has not been installed.
*
* @link https://developer.wordpress.org/advanced-administration/wordpress/wp-config/#table-prefix
*/
$table_prefix = 'wp_';
Come vedi, di default il prefisso è wp_, ed è noto a tutti, hacker compresi.
Cambiandolo, renderai il lavoro degli hacker più complicato.
La variabile $table_prefix è il valore che viene inserito davanti ai nomi delle tue tabelle del database.
Modifica questo valore se desideri utilizzare un prefisso diverso da wp_ per le tue tabelle del database.
Gestire la modalità di debug
Permette di gestire la modalità di debug.
/**
* 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.
*
* For information on other constants that can be used for debugging,
* visit the documentation.
*
* @link https://developer.wordpress.org/advanced-administration/debug/debug-wordpress/
*/
define( 'WP_DEBUG', false );
/* Add any custom values between this line and the "stop editing" line. */
Basta impostare a true il WP_DEBUG.
define( 'WP_DEBUG', true );
Questa funzionalità è da attivare quando il sito WordPress ha dei problemi per poterli risolvere, oppure in fase di sviluppo.
Il wp-config-sample.php
Il file wp-config-sample.php è un file di esempio da cui si può partire per creare il file wp-config.php finale.
Ecco il codice della versione 6.8 di WordPress.
<?php
/**
* The base configuration for WordPress
*
* The wp-config.php creation script uses this file during the installation.
* You don't have to use the website, you can copy this file to "wp-config.php"
* and fill in the values.
*
* This file contains the following configurations:
*
* * Database settings
* * Secret keys
* * Database table prefix
* * ABSPATH
*
* @link https://developer.wordpress.org/advanced-administration/wordpress/wp-config/
*
* @package WordPress
*/
// ** Database settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define( 'DB_NAME', 'database_name_here' );
/** Database username */
define( 'DB_USER', 'username_here' );
/** Database password */
define( 'DB_PASSWORD', 'password_here' );
/** Database 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}.
*
* You can change these at any point in time to invalidate all existing cookies.
* This will force all users to have to log in again.
*
* @since 2.6.0
*/
define( 'AUTH_KEY', 'put your unique phrase here' );
define( 'SECURE_AUTH_KEY', 'put your unique phrase here' );
define( 'LOGGED_IN_KEY', 'put your unique phrase here' );
define( 'NONCE_KEY', 'put your unique phrase here' );
define( 'AUTH_SALT', 'put your unique phrase here' );
define( 'SECURE_AUTH_SALT', 'put your unique phrase here' );
define( 'LOGGED_IN_SALT', 'put your unique phrase here' );
define( 'NONCE_SALT', 'put your unique phrase here' );
/**#@-*/
/**
* 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!
*
* At the installation time, database tables are created with the specified prefix.
* Changing this value after WordPress is installed will make your site think
* it has not been installed.
*
* @link https://developer.wordpress.org/advanced-administration/wordpress/wp-config/#table-prefix
*/
$table_prefix = 'wp_';
/**
* 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.
*
* For information on other constants that can be used for debugging,
* visit the documentation.
*
* @link https://developer.wordpress.org/advanced-administration/debug/debug-wordpress/
*/
define( 'WP_DEBUG', false );
/* Add any custom values between this line and the "stop editing" line. */
/* That's all, stop editing! Happy publishing. */
/** Absolute path to the WordPress directory. */
if ( ! defined( 'ABSPATH' ) ) {
define( 'ABSPATH', __DIR__ . '/' );
}
/** Sets up WordPress vars and included files. */
require_once ABSPATH . 'wp-settings.php';
Altre configurazioni possibili?
Se vuoi approfondire, ecco altre configurazioni possibili.


