您的位置:首页»WordPress 教程, 新手入门»  wp-config.php 文件详解

wp-config.php 文件详解

和其他 PHP 程序一样,WordPress 也是通过一个 config.php 文件来连接 MySQL 数据库的。我们使用著名的 Wordpress 五分钟安装教程安装 WordPress,它会在网站根目录为我们自动生成一个 wp-config.php 文件,当然,我们也可以事先利用 wp-config-sample.php 另存为一个 wp-config.php 文件。那么,我们就一起来看看这个神秘的 wp-config.php 吧!

  1. MySQL 设置
  2. define('DB_NAME', 'putyourdbnamehere');    // 数据库名称
    define('DB_USER', 'usernamehere');     // MySQL 用户名
    define('DB_PASSWORD', 'yourpasswordhere'); // 数据库密码
    define('DB_HOST', 'localhost');    // 数据库地址,99% 的情况下,您不需要修改这一项

    当然,很多服务器或虚拟主机都有自己特定的数据库地址,请看下表

    1and1 db12345678
    AN Hosting localhost
    BlueHost localhost
    DreamHost mysql.example.com
    GoDaddy h41mysql52.secureserver.net
    HostGator localhost
    HostICan localhost
    ICDSoft localhost:/tmp/mysql5.sock
    LaughingSquid localhost
    MediaTemple GridServer internal-db.s44441.gridserver.com
    one.com localhost
    pair Networks dbnnnx.pair.com
    Yahoo mysql
    Hosts with cPanel localhost
    Hosts with Plesk localhost
    Hosts with DirectAdmin localhost

    以上信息以您主机商的最新信息为准,请参考,如有遗漏,请留言补充。
    也许,您的主机商更改了 MySQL 端口,那么,您需要这样写:

    define('DB_HOST', 'localhost:3307');

    define('DB_HOST', 'mysql.example.com:4454);
  3. 安全密匙(SECURE_KEY)
  4. 从 WordPress2.6 开始,您可以用 AUTH_KEYSECURE_AUTH_KEY,和 LOGGED_IN_KEY这三个密匙加密您的 cookies 信息。在最新的 WordPress2.7 中,又新增了第四个密匙 NONCE_KEY,您可以到 http://api.wordpress.org/secret-key/1.1/ 为您生成这四个安全密匙,将得到的密匙填在以下位置

    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');// 填写您独一无二的密匙
  5. 设置域名和 WordPress 路径
  6. 如果您修改自己 Blog 的域名,可通过下面两行代码进行硬设置,注意最后不要带“ /”并取消注释

    // define('WP_SITEURL', 'http://domainname/wordpress');
    // define('WP_HOME', 'http://domainname');
  7. 设置您的 WordPress 语言
  8. 我们可以通过修改 define (‘WPLANG’, ”); 来设置我们的 Blog 语言,如果您和我一样使用简体中文,那么,则修改成:

    define ('WPLANG', 'zh_CN');
  9. 修改 WordPress 数据库前缀
  10. 如果您给每个安装不同的前缀,那么可以在一个数据库里安装多个网站。

    $table_prefix  = 'wp_';   // 仅限数字、字母和下划线!

    设置 wp-content 目录
    从 WordPress2.6 开始,WordPress 允许我们修改 wp-content 目录的路径,例如,我们可以将 wp-content 目录放在 WordPress 安装目录外:

    define( 'WP_CONTENT_DIR', $_SERVER['DOCUMENT_ROOT'] . '/outsidewp/wp-content' );

    甚至,我们可以用 URI 来指定 wp-content 目录路径:

    define( 'WP_CONTENT_URL', 'http://example/blog/wp-content');

当然 wp-config.php 文件还有其他高级功能,我们将在 eachSite.org 为您制作的 WordPress 进阶教程中一一为您详细讲解。
如果您还有其他疑问,请留言或加入QQ群:8329980 讨论

2个评论

  • Reply 1 MY-Hou

    December 19th, 2008 at 23:08

    这不是鱼么

    • Reply 2 辐射鱼

      December 19th, 2008 at 23:18

      如假包换,质量保证,嘿嘿……这里也被你翻出来了,囧