WordPress配置文件wp-config.php文件详解

资源外星人导读:本站为大家带来WordPress配置文件 wp-config.php 文件详解文章,更多建站技术,请继续关注资源外星人!

wp-config.php文件是什么?

wp-config.php文件是wordpress建站的配置文件,里面有wordpress的数据库信息,语言信息。 wp-config.php 不是内建的文件,而是在安装过程中自动创建的文件。

开始操作

修改前请备份此文件,一旦错误,网站将不能正常访问,请立即用备份的文件进行恢复。

通过FTP软件,连接至源文件空间,wp-config.php位于网站根目录,和wp-content文件夹位于同一目录,参考下图:

WordPress配置文件wp-config.php文件详解

了解 wp-config.php 文件

首先看一下完整的 wp-config.php 文件

<?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 web site, you can
 * copy this file to "wp-config.php" and fill in the values.
 *
 * This file contains the following configurations:
 *
 * * MySQL settings
 * * Secret keys
 * * Database table prefix
 * * ABSPATH
 *
 * @link https://codex.wordpress.org/Editing_wp-config.php
 *
 * @package WordPress
 */

// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define('DB_NAME', 'database_name_here');

/** MySQL database username */
define('DB_USER', 'username_here');

/** MySQL database password */
define('DB_PASSWORD', 'password_here');

/** 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}
 * 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!
 */
$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 Codex.
 *
 * @link https://codex.wordpress.org/Debugging_in_WordPress
 */
define('WP_DEBUG', 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');

数据库信息配置

数据库信息出现在wp-config.php 文件中 ‘MySQL Settings’ 的下方。您需要替换成自己的数据库信息,包含数据库地址,数据库用户名,数据库密码,数据库名称。

// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define('DB_NAME', 'database_name_here');

/** MySQL database username */
define('DB_USER', 'username_here');

/** MySQL database password */
define('DB_PASSWORD', 'password_here');

/** 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', '');

数据库前缀

默认的是’wp_’, 可以修改成自己想要的。

/**
 * 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_';

使用wp-config.php文件修改wordpress网站的链接

当您需要更换域名,把网站转移到一个新的空间时,可以通过后台的设置更改wordpress的链接。

WordPress配置文件wp-config.php文件详解

也可以通过修改 wp-config.php 文件来实现,只需在 wp-config.php 文件里添加下面两行代码就可以实现。

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

改变文件上传路径

wordpress 默认将媒体文件上传到 /wp-content/uploads/ 路径,可以通过添加下面代码,上传到自定义文件夹中。

define( 'UPLOADS', 'wp-content/media' );

禁止自动更新

wordpress从3.7版本开始,增加了自动更新的功能。自动更新对安全性有好处,但是有时候会出现一些错误,使网站不能正常访问。可以添加下面的代码禁止wordpress自动更新。

define( 'WP_AUTO_UPDATE_CORE', false );

以上就是资源外星人整理的WordPress配置文件 wp-config.php 文件详解全部内容,希望对大家有所帮助!