WordPress配置文件解析

WordPress配置文件解析

WordPress 的核心配置文件是位于网站根目录的 wp-config.php。

若该文件不存在,可将 wp-config-sample.php 复制并重命名为 wp-config.php 后进行编辑。

1. 基础数据库配置
修改以下常量以连接数据库:

php
// ‌** MySQL 设置 – 具体信息来自您正在使用的主机 **‌ //
/** WordPress 数据库的名称 */
define( ‘DB_NAME’, ‘database_name_here’ );

/** MySQL 数据库用户名 */
define( ‘DB_USER’, ‘username_here’ );

/** MySQL 数据库密码 */
define( ‘DB_PASSWORD’, ‘password_here’ );

/** MySQL 主机 */
define( ‘DB_HOST’, ‘localhost’ );

/** 创建数据表时默认的文字编码 */
define( ‘DB_CHARSET’, ‘utf8mb4’ );

/** 数据库整理类型。如不确定请勿更改 */
define( ‘DB_COLLATE’, ” );

2. 安全密钥(Authentication Keys and Salts)
用于加密 Cookie 信息,建议通过 WordPress 官方密钥生成器 获取随机字符串替换下方内容:

php
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’ );

3. 常用优化与调试配置
在 /* That’s all, stop editing! Happy publishing. */ 注释之前添加以下常用配置:

php
/** 设置数据库表前缀,建议修改默认 wp_ 以提高安全性 */
$table_prefix = ‘wp_’;

/** 开启调试模式(开发环境设为 true,生产环境设为 false) */
define( ‘WP_DEBUG’, false );

/** 将错误记录到 /wp-content/debug.log 文件中,而不显示在页面上 */
if ( WP_DEBUG ) {
define( ‘WP_DEBUG_LOG’, true );
define( ‘WP_DEBUG_DISPLAY’, false );
@ini_set( ‘display_errors’, 0 );
}

/** 增加 PHP 内存限制 */
define( ‘WP_MEMORY_LIMIT’, ‘256M’ );

/** 禁用文章修订版本功能,或限制数量(例如只保留最近 5 个) */
define( ‘WP_POST_REVISIONS’, 5 );

/** 设置自动保存间隔(秒) */
define( ‘AUTOSAVE_INTERVAL’, 120 );

/** 强制后台使用 SSL (需服务器支持 HTTPS) */
// define( ‘FORCE_SSL_ADMIN’, true );

/** 禁用文件编辑功能(防止后台直接修改主题/插件代码,提高安全性) */
define( ‘DISALLOW_FILE_EDIT’, true );

注意事项:

‌文件权限‌:建议将 wp-config.php 权限设置为 440 或 400,以防止其他用户读取敏感信息。

‌备份‌:修改前务必备份原文件。

‌编码‌:确保文件保存为 UTF-8 无 BOM 格式,避免中文乱码或头部输出错误。

© 版权声明
THE END
喜欢就支持一下吧
点赞12 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容