You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Rocky Linux 9+PHP8.1环境安装WordPress6.2遇preg_replace错误求助

解决WordPress 6.2安装时PCRE相关致命错误

环境配置

  • Rocky Linux 9
  • PHP 8.1
  • MySQL 8
  • WordPress 6.2

问题描述

全新服务器安装WordPress 6.2时,访问安装页面出现以下错误:

[18-May-2023 01:26:09 UTC] PHP Warning: preg_replace(): Compilation failed: unrecognised compile-time option bit(s) at offset 0 in /var/www/html/wp-includes/class-wpdb.php on line 1535
[18-May-2023 01:26:09 UTC] PHP Warning: preg_split(): Compilation failed: unrecognised compile-time option bit(s) at offset 0 in /var/www/html/wp-includes/class-wpdb.php on line 1538
[18-May-2023 01:26:09 UTC] PHP Fatal error: Uncaught TypeError: count(): Argument #1 ($value) must be of type Countable|array, bool given in /var/www/html/wp-includes/class-wpdb.php:1540
Stack trace:
0 /var/www/html/wp-includes/option.php(199): wpdb->prepare()
1 /var/www/html/wp-includes/l10n.php(63): get_option()
2 /var/www/html/wp-includes/l10n.php(139): get_locale()
3 /var/www/html/wp-includes/l10n.php(868): determine_locale()
4 /var/www/html/wp-includes/class-wp-fatal-error-handler.php(47): load_default_textdomain()
5 [internal function]: WP_Fatal_Error_Handler->handle()
6 {main}
thrown in /var/www/html/wp-includes/class-wpdb.php on line 1540

已更新pcre2到最新版本10.40,问题仍存在。

可行解决方案

1. 禁用PCRE JIT编译

编辑PHP配置文件(通常为/etc/php.ini或/etc/php.d/zz-pcre.ini),添加或修改:

pcre.jit=0

保存后重启PHP-FPM服务:

systemctl restart php-fpm

PCRE的JIT编译可能与特定环境存在兼容性问题,禁用后可解决正则表达式编译错误。

2. 验证并修复WordPress文件完整性

下载官方WordPress 6.2包,覆盖现有核心文件(保留wp-config.php和wp-content目录):

cd /tmp
wget https://wordpress.org/wordpress-6.2.tar.gz
tar xzf wordpress-6.2.tar.gz
cp -r wordpress/* /var/www/html/
chown -R apache:apache /var/www/html/

若原始WordPress文件存在损坏,覆盖后可恢复正常的正则表达式逻辑。

3. 检查PHP与PCRE库的兼容性

执行以下命令查看PHP关联的PCRE版本:

php -i | grep -A 5 "PCRE Library Version"

确认输出的版本与系统安装的pcre2版本一致(应为10.40)。若不一致,说明PHP使用了内置的旧版PCRE库,需重新编译PHP或更换为系统库关联的PHP包(比如使用Remi仓库的预编译PHP)。

4. 重新安装PCRE2相关依赖

重新安装pcre2及开发包,修复可能的库损坏:

dnf reinstall pcre2 pcre2-devel

安装完成后重启PHP-FPM服务,确保新库被加载。

5. 切换PHP版本测试

尝试更换PHP版本至8.0或8.2,验证是否为PHP 8.1与PCRE2的兼容性问题:

# 安装PHP 8.2(需先启用Remi仓库)
dnf install -y https://rpms.remirepo.net/enterprise/remi-release-9.rpm
dnf module enable php:remi-8.2 -y
dnf install php php-fpm php-mysqlnd
systemctl enable --now php-fpm

切换后重新访问WordPress安装页面,查看错误是否消失。


内容的提问来源于stack exchange,提问作者Josh Whitlow

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.21 18:05:22