高级管理文档

调试 WordPress 多站点网络

💡 云策文档标注

概述

本文档针对 WordPress 多站点网络(Multisite)调试,主要解决因数据库全局表缺失或配置错误导致的网络故障。面向开发者,提供从配置检查到数据库修复的实用步骤。

关键要点

  • 网络错误通常源于数据库全局表(如 wp_blogs、wp_site)缺失或配置不当。
  • 检查 wp-config.php 文件中的数据库详情、SUBDOMAIN_INSTALL、MULTISITE 常量、$base 变量和表前缀。
  • 确保代码位置正确,避免在 require_once(ABSPATH . 'wp-settings.php') 后添加代码。
  • 对于子域名站点 404 错误,需启用 Apache 的 mod_rewrite 并调整 AllowOverride 设置。
  • 验证数据库是否包含所有网络表,必要时手动插入数据以修复空表问题。
  • 注意数据库用户权限、数据库排序规则(collation)和 .htaccess 错误日志。

代码示例

INSERT INTO wp_site VALUES ( 1, 'domain.com', '/' );
INSERT INTO wp_blogs VALUES( 1, 1, 'domain.com', '/', '2015-01-01', '2015-01-01', 1, 0, 0, 0, 0, 0 );
INSERT INTO wp_sitemeta VALUES( 1, 1, 'site_admins', 'a:1:{i:1;s:5:"admin";}' );

注意事项

  • 在创建网络前,确认主机支持相关功能并满足技术要求。
  • 升级 WordPressMU 到 3.0+ 时,注意潜在的数据库排序规则问题。
  • 监控 Apache 日志以排查 .htaccess 指令错误,如 RewriteRule 被禁止。

📄 原文内容

Debugging a WordPress Network

If you have reached this page, chances are you have received an error in your WordPress network. This failure occurs when WordPress cannot find one or more of the global tables for the network in the database.

On some shared web hosts, the host has disabled the functionality from running. It is always best to check with your web host before creating a network to make sure your web host account fulfills the technical requirements.

If You just installed your network

Check your wp-config.php file for:

  • correct database details
  • SUBDOMAIN_INSTALL constant
  • MULTISITE constant
  • $base variable
  • table prefix

You should not have anything after

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

Move any code that is after

require_once(ABSPATH . 'wp-settings.php');

to above the stop editing line.

Mod_rewrite not working

The main site works, but 404 errors show up when trying to access added child subdomain sites. An Ubuntu with Apache HTTPD installation needs these steps:

sudo a2enmod rewrite
sudo nano /etc/apache2/sites-avail/default

and change in two places the ‘AllowOverride None’ to ‘AllowOverride all’

/etc/init.d/apache2 restart

to restart apache2. Note that on more modern versions of Ubuntu the following syntax is preferred (for restarting services such as Apache – also note that in either case you may need to use prepend sudo):

service apache2 restart

Check the database

Assuming all that is correct, check the database itself and see if all the extra network tables were created. The tables are:

  • wp_blogs
  • wp_blogmeta
  • wp_blog_versions
  • wp_registration_log
  • wp_signups
  • wp_site
  • wp_sitemeta

If you have these DB tables or added them manually but wp_site and/or wp_blogs is empty, you may have to run some SQL queries to insert rows for your main site. Be sure to adjust the table prefixes, domains, dates, username, and other parts of the queries below to match your installation.

INSERT INTO wp_site VALUES ( 1, 'domain.com', '/' );
# change domain.com to the full domain of your original site and / to the path

INSERT INTO wp_blogs VALUES( 1, 1, 'domain.com', '/', '2015-01-01', '2015-01-01', 1, 0, 0, 0, 0, 0 );
# change domains.com and / to domain and path of your site. Change dates if you want.

INSERT INTO wp_sitemeta VALUES( 1, 1, 'site_admins', 'a:1:{i:1;s:5:"admin";}' );
# Sets the admin user as a Super Admin. Change "admin" to your user_login. 
# Change "s:5" to "s:#" where # is the number of characters in user_login.

If new site creation suddenly stopped working

Please take a look at your database as above. Double-check that the location of the database server hasn’t changed, or is so, that you’ve updated your wp-config.php file.

Other lesser-known issues

Check that the database user has ALL permissions on the database.

Also, on very few upgrades from WordPressMU to 3.0 and up, a few users experienced a problem with creating new sites and receiving errors. This turned out to be a database collation issue.

Check that the .htaccess instructions are not throwing up errors in the Apache logs.

Like this one:

Options FollowSymLinks or SymLinksIfOwnerMatch is off which implies that RewriteRule directive is forbidden:

This will result in a Network install appearing to fail and may show WP errors like

One or more database tables are unavailable. The database may need to be repaired.

Related Articles

External Links