Voyons une méthode pour configurer plusieurs environnements dans le fichier wp-config.php
pour un site WordPress. Dans cet exemple, nous gérons un site en local (ici avec les paramètres pour Local By Flywheel), un site de préproduction et le site en production.
<?php /** * The base configuration for WordPress - wp-config.php * Custom by wprock.fr to manage multi-environment * * Link: https://wprock.fr/blog/wordpress-plusieurs-environnements-wp-config-php * Codex: https://wordpress.org/support/article/editing-wp-config-php/ */ switch ( $_SERVER['HTTP_HOST'] ) { // Staging environment settings example case 'staging.wprock.fr': define( 'DB_NAME', 'database_name_here' ); define( 'DB_USER', 'username_here' ); define( 'DB_PASSWORD', 'password_here' ); define( 'DB_HOST', 'localhost' ); // Config Debug and log define( 'WP_DEBUG', true ); define( 'WP_DEBUG_LOG', true ); define( 'WP_DEBUG_DISPLAY', true ); break; // Local by flywheel settings example case 'wprock.local': define( 'DB_NAME', 'local' ); define( 'DB_USER', 'root' ); define( 'DB_PASSWORD', 'root' ); define( 'DB_HOST', 'localhost' ); // Config Debug and log define( 'WP_DEBUG', true ); define( 'WP_DEBUG_LOG', true ); define( 'WP_DEBUG_DISPLAY', true ); break; // Production settings example default: define( 'DB_NAME', 'database_name_here' ); define( 'DB_USER', 'username_here' ); define( 'DB_PASSWORD', 'password_here' ); define( 'DB_HOST', 'localhost' ); break; } // For settings available for all environments define( 'DB_CHARSET', 'utf8' ); define( 'DB_COLLATE', '' ); $table_prefix = 'wp_'; /**#@+ * Authentication Unique Keys and Salts. * You can generate here: https://api.wordpress.org/secret-key/1.1/salt/ */ define( 'AUTH_KEY', '@U_N G;HKz3#CX+Vkd~p6VzL<XwLdvH;]6KF/_g7wd)VzVe}x-?R>]d4`zgxI_S|' ); define( 'SECURE_AUTH_KEY', 'c/Ri:;,L]Xpa @$-H!x!_#zMA-4VsSw5WtI[5}bV1_p$[>6fgx]]C9X7|[email protected]' ); define( 'LOGGED_IN_KEY', '{r2j=yb+0l}a1nb`J9-cfCg`8Eh#jZ:te8df%Uv-]-lLDt?36.`+kxH0_+|BMwCG' ); define( 'NONCE_KEY', ' ;1IegwX>&rK|L|d`jkX%c`#{~cS%*NH&=Y&ViLw),f8)G*n?$5K~IIZiccwZpJ-' ); define( 'AUTH_SALT', ',TJLb(Qh]X8Zq}_,Yoz)*,D#Axr#O/BogMH9|Bn$W~kQfonX>[email protected]([email protected] ' ); define( 'SECURE_AUTH_SALT', '4GX9VT%.//; A+qkb)c}+QFTc(qi&N[-~)P=Q FmO#()peL2/pXYF=yv[e>**FZg' ); define( 'LOGGED_IN_SALT', 'aY7z>F>A3*a`s?7jzCyGo&FY~#=]VVD+LoNff^wAxgo~8dEi!FWT kV6FLFUCLO|' ); define( 'NONCE_SALT', '>jj/d~7++?CmCuU7Ad6ev{12(vC!IY%lgGxf8vWBz,e6<xmBQeJx&5A|rg--W$:3' ); /* That's all, stop editing! Happy publishing. */ if ( ! defined( 'ABSPATH' ) ) { define( 'ABSPATH', __DIR__ . '/' ); } require_once ABSPATH . 'wp-settings.php';