9

My server configurations:

[root@server ~]# php -v 
PHP 7.0.22 (cli) (built: Aug 7 2017 16:18:27) ( NTS ) 

[root@server ~]# nginx -v 
nginx version: nginx/1.10.2

OS: CentOS 7.3.1611 (Core)

Details of my YUM installation:

[root@server ~]# yum list installed | grep php
php70u-cli.x86_64                       7.0.22-2.ius.centos7           @ius     
php70u-common.x86_64                    7.0.22-2.ius.centos7           @ius     
php70u-fpm.x86_64                       7.0.22-2.ius.centos7           @ius     
php70u-fpm-nginx.noarch                 7.0.22-2.ius.centos7           @ius     
php70u-mysqlnd.x86_64                   7.0.22-2.ius.centos7           @ius     
php70u-pdo.x86_64                       7.0.22-2.ius.centos7           @ius  

Here is the details of the investigation: I tried executing following code in test.php:

Here are my system details: PHP Version => 7.0.22 OS: I am trying to execute following code in test2.php:

<?php
$arr = array('a' => 1, 'b' => 2, 'c' => 3, 'd' => 4, 'e' => 5);
echo json_encode($arr);
?>

And, getting the following error:

[root@server ~]# php /tmp/test2.php
**PHP Fatal error:  Uncaught Error: Call to undefined function json_encode() in /tmp/test2.php:3**

How to resolve this?

Dibya Sahoo
  • 839
  • 3
  • 9
  • 30

3 Answers3

14

I run the following command to install json for php7 and it worked perfectly fine.

[root@server dbs]# sudo yum install php70u-json
Dibya Sahoo
  • 839
  • 3
  • 9
  • 30
4

For me was enough with:

 yum install php-json

I'm using php7.2

Evan
  • 1,004
  • 11
  • 12
2

Install:

  php70u-json.x86_64 0:7.0.32-1.ius.centos7

Result:

Complete!
[root@server1 ~]# systemctl restart httpd
Unheilig
  • 16,196
  • 193
  • 68
  • 98