如何修复 Ubuntu PHP Call to undefined function mb_internal_encoding()
问题:
当你在 PHP 日志中看到以下错误消息时:
php_mb_internal_encoding_error.txt
2022/12/22 12:57:20 [error] 1908680#1908680: *9092980 FastCGI sent in stderr: "PHP message: PHP Fatal error: Uncaught Error: Call to undefined function mb_internal_encoding() in /var/www/snappymail/v/0.0.0/include.php:90
Stack trace:
#0 /var/www/index.php(11): include()
#1 {main}
thrown in /var/www/snappymail/v/0.0.0/include.php on line 90" while reading response header from upstream, client: ::ffff:77.7.108.195, server: mydomain.com, request: "GET /?admin HTTP/2.0", upstream: "fastcgi://unix:/var/run/php/php8.2-fpm.sock:", host: "mydomain.com"解决方案
缺失的函数 mb_internal_encoding() 来自 PHP mbstring 模块。
要安装它,首先你需要识别运行给定脚本的 PHP 版本。这可以通过查看给定域名的 webserver 配置文件或查看错误日志来完成。在这种情况下,我们可以从 upstream: "fastcgi://unix:/var/run/php/php8.2-fpm.sock:" 识别出 PHP 版本是 8.2
如果你无法识别正确的版本,我建议为每个已安装的 PHP 版本安装 mbstring,你可以使用 sudo dpkg --get-selections | grep php 查看。
给定版本号,我们可以从 Ubuntu/Debian 包源安装 mbstring 扩展:
install_php_mbstring.sh
sudo apt -y install php8.2-mbstring根据你的配置,你可能还需要重启 webserver 和/或 PHP-FPM 服务。我建议先不重启试试,然后重启 webserver,如果你使用 PHP-FPM,重启你的 PHP 版本的 PHP-FPM。如果这不起作用,你总是可以重启。
之后,错误消息应该已经消失 - 有时你需要安装额外的 PHP 模块,最好只是查看错误日志以发现更多缺失函数或其他与缺失扩展相关的错误。
Check out similar posts by category:
PHP
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow