PHP7.4编译启用mbstring的mbregex

将PHP更新升级到最新的7.4版本之后,发现部分程序页面显示出问题,或直接500错误;经过查看日志,发现是调用mbstring相关函数失败导致,部分错误如下:

[root@JP-BLG apache]# tail -f logs/mail-error-2020_10_30.log
[Fri Oct 30 19:07:10.161064 2020] [php7:error] [pid 26821] [client 183.129.232.18:6006] PHP Fatal error:  Uncaught Error: Call to undefined function mb_split() in /path/www/postfixadmin/lib/smarty/libs/plugins/shared.mb_str_replace.php:47\nStack trace:\n#0 /path/www/postfixadmin/lib/smarty/libs/plugins/modifier.replace.php(34): smarty_mb_str_replace()\n#1 /path/www/postfixadmin/templates_c/298cf19cd0da4910f608e622b12cf6e7c686ab71_0.file.list.tpl.php(135): smarty_modifier_replace()\n#2 /path/www/postfixadmin/lib/smarty/libs/sysplugins/smarty_template_resource_base.php(123): content_5ead29218ea276_70462996()\n#3 /path/www/postfixadmin/lib/smarty/libs/sysplugins/smarty_template_compiled.php(114): Smarty_Template_Resource_Base->getRenderedTemplateCode()\n#4 /path/www/postfixadmin/lib/smarty/libs/sysplugins/smarty_internal_template.php(216): Smarty_Template_Compiled->render()\n#5 /path/www/postfixadmin/lib/smarty/libs/sysplugins/smarty_internal_template.php(385): Smarty_Internal_Template->render()\n#6 /path/www/postfixadmin/templates_c/e0698bcff4fc477ab184abd3affc2831f492d1eb_0.file.index.tpl.php(45): Smarty_Internal_Template in /path/www/postfixadmin/lib/smarty/libs/plugins/shared.mb_str_replace.php on line 47, referer: https://mail.xvcat.com/postfix/edit.php?table=admin

 

由于mbstring本身是开启的,经过一番查找,是由于PHP在7.4版本之后,将mbregex相关的功能改为外部调用Oniguruma来实现,见管网说明:https://www.php.net/manual/en/mbstring.installation.php

知道原因之后,故先安装 Oniguruma 来支持mbregex:

wget https://github.com/kkos/oniguruma/releases/download/v6.9.5_rev1/onig-6.9.5_rev1.tar.gz
tar zxf onig-6.9.5_rev1.tar.gz -C /usr/local/src/
cd /usr/local/src/onig-6.9.5/
CFLAGS="-fPIC -O3" ./configure --prefix=/usr/local/onig
make -j `cat /proc/cpuinfo | grep processor | wc -l` && make install

然后重启编译配置PHP时,在PKG_CONFIG_PATH中添加onig的搜索路径,然后安装即可解决问题。

cd /usr/local/src/php-7.4.12/
PKG_CONFIG_PATH="/usr/local/lib/pkgconfig:/usr/local/libxml2/lib/pkgconfig:/usr/local/openssl/lib/pkgconfig:/usr/local/pcre2/lib/pkgconfig:/usr/local/curl/lib/pkgconfig:/usr/local/gd/lib/pkgconfig:/usr/local/lib64/pkgconfig:/usr/local/onig/lib/pkgconfig" CFLAGS="-fPIC -O3" LDFLAGS="-Wl,--enable-new-dtags,-rpath=/usr/local/lib:/usr/local/openssl/lib:/usr/local/curl/lib:/usr/local/pcre2/lib:/usr/local/libxml2/lib:/usr/local/gd/lib:/usr/local/lib64" ./configure --prefix=/usr/local/php7 --with-apxs2=/usr/local/apache/bin/apxs --enable-fpm --with-fpm-user=apache --with-fpm-group=apache --with-fpm-systemd --enable-sigchild --enable-libgcc --with-openssl --with-external-pcre --with-pcre-jit --with-zlib --with-bz2=/usr/local/ --enable-calendar --with-curl --enable-gd --with-external-gd --enable-gd-jis-conv --with-gettext --with-mhash=/usr/local/ --with-mysqli=mysqlnd  --with-mysql-sock=/path/mariadb/mysql.sock --enable-pdo --with-pdo-mysql=mysqlnd --enable-mysqlnd --with-libedit=/usr/local/ --with-readline=/usr/local/ --with-expat=/usr/local/ --with-iconv-dir=/usr/local/ --with-zip --enable-mbstring=all --enable-bcmath --enable-exif --enable-ftp --enable-opcache --enable-intl --enable-pcntl --enable-shmop --enable-soap --enable-sockets --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-inline-optimization --enable-maintainer-zts --enable-zend-signals --with-config-file-path=/usr/local/php7
make -j `cat /proc/cpuinfo | grep processor | wc -l` && make install
systemctl reload httpd

查看页面可正常显示,亦不会报错。

《PHP7.4编译启用mbstring的mbregex》有1条评论

  1. Excellent! Brings back so many fond memories. Garden Way and what it stood for is as relevant today as it was then. Bess Stirling Palladin

    回复

发表评论

error: Content is protected !!