PHP message: PHP Fatal error: Uncaught Error: Call to undefined function json_encode()_fastcgi sent in stderr: "php message: php fatal er

前言

  • 腾讯云:CentOS Linux release 8.5.2111
  • nginx:1.14.1
  • php:7.2.24。参考这里的php安装

查看错误

查看nginx的错误日志可以看到php的错误日志。

  • nginx日志位置:/var/log/nginx
  • nginx错误日志:error.log

错误信息

2023/01/12 20:49:51 [error] 2198574#0: *185124 FastCGI sent in stderr: "PHP message: PHP Fatal error:  Uncaught Error: Call to undefined function json_encode() in /data/www/aaa/install.php:332
Stack trace:
#0 {main}
  thrown in /data/www/aaa/install.php on line 332" while reading response header from upstream, client: 172.21.16.8, server: aaa.com, request: "POST /install.php?refresh HTTP/1.0", upstream: "fastcgi://127.0.0.1:9000", host: "aaa.com:443", referrer: "https://aaa.com/install.php?refresh"
  • 1
  • 2
  • 3
  • 4

解决办法

安装php-json

yum查看php-json的可安装版本

shell> yum list php-json
Last metadata expiration check: 3:05:13 ago on Fri 13 Jan 2023 05:58:03 AM CST.
Available Packages
php-json.x86_64                                                                       7.2.24-1.module_el8.2.0+313+b04d0a66                                                                        AppStream
  • 1
  • 2
  • 3
  • 4

或者

shell> yum info php-json
Last metadata expiration check: 3:06:14 ago on Fri 13 Jan 2023 05:58:03 AM CST.
Installed Packages
Name         : php-json
Version      : 7.2.24
Release      : 1.module_el8.2.0+313+b04d0a66
Architecture : x86_64
Size         : 44 k
Source       : php-7.2.24-1.module_el8.2.0+313+b04d0a66.src.rpm
Repository   : @System
From repo    : AppStream
Summary      : JavaScript Object Notation extension for PHP
URL          : http://www.php.net/
License      : PHP
Description  : The php-json package provides an extension that will add
             : support for JavaScript Object Notation (JSON) to PHP.
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16

yum 安装 php-json

shell> yum install php-json
  • 1